Chef And Plants
All submissions for this problem are available.
Chef is the richest person in his town Chefinia. Chef has a big garden along with greenhouse.
Garden has N plants, each with a height hi (0 ≤ i ≤ N-1).
Now chef wants to trim some of the plants to make all the plants of the same height.
In one move, chef can select a range L,R (0 ≤ L ≤ R ≤ N-1) and reduce the height of all plants in the range by 1.
Chef is feeling lazy and wants to know what is the minimum number of moves needed for chef to make all plants of equal length. Please help him find the answer.
For each test case, output a single integer – the minimum no. of moves required.
Input: 2 3 1 2 3 5 12 18 21 10 9 Output: 2 12
Example case 1.
In first case, we can first choose (2,2) and then (1,2)
1 2 3 -> 1 2 2 -> 1 1 1
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYPY, PYTH, PYTH 3.5, RUBY, SCALA, SCM chicken, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.