#P10971. Cookies
Cookies
Problem Description
Santa Claus has a total of cookies and plans to give them all to children.
Each child has a greed value. The greed value of the -th child is .
If there are children who receive more cookies than the -th child, then the -th child will have resentment of .
Given , , and the sequence , please help Santa Claus find a distribution such that each child gets at least one cookie, and the total resentment of all children is minimized.
Input Format
The first line contains two integers .
The second line contains integers representing .
Output Format
The first line contains one integer, the minimum total resentment.
The second line contains integers separated by spaces, representing the number of cookies each child receives. If there are multiple solutions, output any one of them.
3 20
1 2 3
2
2 9 9
Hint
Constraints: , , .
Translated by ChatGPT 5