#P6236. [COCI 2010/2011 #1] LJUTNJA
[COCI 2010/2011 #1] LJUTNJA
Description
Kindergarten children received a big package with candies, and now these candies need to be distributed to children.
Each child has given an expected number of candies. If a child does not receive their expected amount , 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 candies but only gets . He is short of , so his anger level is . 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 lines.
The first line contains two integers .
The next lines each contain one integer. The integer on line is the expected value of the -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 candies and people. Give each child the number of candies they want minus , that is, give candies respectively. Then each person is short of one candy, so each person’s anger level is . With people, the total is . The answer is optimal.
Constraints
- For of the testdata, , , and the result does not exceed .
- For of the testdata, , , and the result does not exceed .
Translated by ChatGPT 5
京公网安备 11011102002149号