Comments

Good stuff. Cheers

On game_changer007problem A div 1, 11 years ago
+1

Let the elements of the array be a[0],a[1]...a[n-1]. Since the sum of each pair of consecutive elements has to be the same, if a[0] decreases by 1, a[1] increases by 1 and so on alternately for all a[n-1]. So if n is even there can be no net transfer of coins from the array to the robber. If n is odd however, see that sum of all elements decreases by 1 when we repeat the above process. This coin can be transferred to the robber.

The final greedy process will be 1 coin transferred from a[0]->a[1], 1 coin transferred from a[2]->a[3].....a[n-3]->a[n-2] and a[n-1]->ROBBER. This process takes (n+1)/2 steps for each coin gained and pairwise sum retained. So you have to find how many times this process can be completed in 'm' operations , k times.

Also make sure none of a[0],a[2],a[4]....a[n-1] become negative.

MY SOLUTION