Official algorithmic problem description and constraints.
To celebrate his recovery, k1o0n has baked an enormous π metres long potato casserole.
Turns out, Noobish_Monk just can't stand potatoes, so he decided to ruin k1o0n's meal. He has cut it into π pieces, of lengths π1,π2,β¦,ππ meters.
k1o0n wasn't keen on that. Luckily, everything can be fixed. In order to do that, k1o0n can do one of the following operations:
Help k1o0n to find the minimum number of operations he needs to do in order to merge the casserole into one piece with length π.
For example, if π=5, π=2 and π=[3,2], it is optimal to do the following:
Detailed video explanations, mathematical intuition, and clean C++ implementation code.