Sorting Pancakes Codeforces Solution | Codeforces Problem Solution 2022
Nastya baked pancakes and spread them on dishes. The dishes are in a row and numbered from left to right. She put pancakes on the dish with the index .
Seeing the dishes, Vlad decided to bring order to the stacks and move some pancakes. In one move, he can shift one pancake from any dish to the closest one, that is, select the dish () and do one of the following:
- if , put the pancake on a dish with the previous index, after this move and ;
- if , put the pancake on a dish with the following index, after this move and .
Vlad wants to make the array non-increasing, after moving as few pancakes as possible. Help him find the minimum number of moves needed for this.
The array is called non-increasing if for all from to .
The first line of the input contains two numbers and () — the number of dishes and the number of pancakes, respectively.
The second line contains numbers (), the sum of all is equal to .
Print a single number: the minimum number of moves required to make the array non-increasing.
Join Now for Solution:-
No comments:
Post a Comment