#P10971. Cookies

Cookies

Problem Description

Santa Claus has a total of MM cookies and plans to give them all to NN children.

Each child has a greed value. The greed value of the ii-th child is gig_i.

If there are aia_i children who receive more cookies than the ii-th child, then the ii-th child will have resentment of gi×aig_i\times a_i.

Given NN, MM, and the sequence gg, 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 N,MN, M.

The second line contains NN integers representing g1,g2,,gng_1, g_2, \dots, g_n.

Output Format

The first line contains one integer, the minimum total resentment.

The second line contains NN 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: 1N301\leq N\leq 30, NM5000N\leq M\leq 5000, 1gi1071\leq g_i\leq 10^7.

Translated by ChatGPT 5