#P6236. [COCI 2010/2011 #1] LJUTNJA

[COCI 2010/2011 #1] LJUTNJA

Description

Kindergarten children received a big package with mm candies, and now these candies need to be distributed to nn children.

Each child has given an expected number of candies. If a child does not receive their expected amount aia_i, the child will get angry. For each missing candy, the child’s anger increases. You can assume the anger level equals the square of the number of candies they are short of.

For example, Mirko wants to get 3232 candies but only gets 2929. He is short of 33, so his anger level is 99. Unfortunately, there are not enough candies to satisfy all children’s expectations. Therefore, we should choose an optimal distribution method so that the sum of all children’s anger levels is minimized.

Input Format

The input has n+1n+1 lines.

The first line contains two integers m,nm, n.

The next nn lines each contain one integer. The integer on line i+1i+1 is the expected value aia_i of the ii-th child.

Output Format

The output has one line.

Output one integer, which is the minimum total anger level.

10 4
4
5
2
3
4

Hint

Explanation for Sample Input/Output 1

There are 1010 candies and 44 people. Give each child the number of candies they want minus 11, that is, give 3,4,1,23, 4, 1, 2 candies respectively. Then each person is short of one candy, so each person’s anger level is 12=11^2 = 1. With 44 people, the total is 1×4=41 \times 4 = 4. The answer 44 is optimal.


Constraints

  • For 40%40\% of the testdata, n5000n \leq 5000, m30m \leq 30, and the result does not exceed 5×1085 \times 10^8.
  • For 100%100\% of the testdata, 1n1051 \leq n \leq 10^5, 1m2×1091 \leq m \leq 2 \times {10}^9, and the result does not exceed 26412^{64}-1.

Translated by ChatGPT 5