Chocolate Cake
Time limit1sMemory limit1024 MB
Given a cake of 2N pieces, add toppings of size M to pieces so that the largest taste gap between the two halves over all N cuts is as small as possible.
- Level
Medium6 of 10
- Topics
- Array, Prefix sum, Math
- Solved
- No attempts yet
Problem
There is a round cake made of fan-shaped pieces of the same size and area. The pieces are numbered to in clockwise order, and initially the taste of piece is .
Chaewan and Heewon want to split the cake in half. To cut the cake, Chaewan picks one integer with , then divides the cake into the part containing pieces and the part containing the remaining pieces. The taste of each part is the sum of the tastes of the pieces it contains.
Chaewan wants to eat the tastier part, so he will choose, among the possible cuts, the one that maximizes the difference between the tastes of the two parts.
Heewon sees through this plan. He can place chocolate toppings on the pieces so that the difference between the two parts is as small as possible after Chaewan cuts the cake. Each topping placed on a piece raises that piece's taste by . A piece can get several toppings, and several pieces can get toppings at the same time. However, the maximum number of toppings on a single piece is .
Find a way to place the toppings so that Heewon can split the cake as evenly as possible.
Input
The first line contains two integers and separated by a space. ;
The next line contains integers , , , , separated by spaces.
Output
On the first line, print the smallest possible difference in taste.
On the next line, print integers , , , , separated by spaces. is the number of chocolate toppings placed on piece , and it must satisfy . The minimum difference can always be reached within these limits.
If several outputs reach the minimum, print any of them.