you go beach idea build great sand castle head the beach threedimensional imagine decribed line spot pile sand pillar spot number 1 infinity leave right obviously sand beach bring n pack sand let height hi sand pillar spot number sand pack spend you can not split sand pack multiple pillar sand single there fence height equal height pillar h sand pack leave spot prevent sand going finally end follow condition build castle h1H sand leftmost spot fence for hihi11 large difference height neighboring pillar lead sand fall higher low do not want happen want spend sand bring as infinite spot build possible come valid castle structure though want castle compact possible your task calculate minimum number spot occupy aforementioned condition hold