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:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.