luogu#P7926. 「EVOI-RD2」大胃王
「EVOI-RD2」大胃王
Problem Description
It is time to eat again, and Big Eater is having trouble deciding what to eat.
There are ingredients, each with a certain weight. Big Eater can split these ingredients into any number of contiguous segments, and then pair each segment with a staple food of weight . The disharmony of a segment is defined as the square of (the sum of ingredient weights in this segment minus the weight of the staple food, which is ). The disharmony of a meal is the sum of the disharmony values of all segments.
Do not worry about how much food there is, because Code (pinyin: mou Code) is a Big Eater, so no matter how much you make, he can finish it.
Next, Code challenges you to answer the minimum and second minimum disharmony of the meal made from the first dishes. If you answer correctly, you will get the chance to share this meal with him.
When two different splitting methods produce the same minimum disharmony, output the two minimum disharmony values. That is, the output is not necessarily the strictly second minimum disharmony.
Input Format
The first line contains two positive integers and , meaning there are ingredients and the weight of each staple food is .
The second line contains integers, where the -th integer represents the weight of the -th ingredient .
Output Format
Output a total of lines.
The first line contains one integer, the minimum disharmony for the meal made from the first dish.
On the -th line, output two integers: the minimum and second minimum disharmony for the meal made from the first dishes, separated by a space.
5 5
3 6 2 4 8
4
5 16
13 14
6 14
15 23
10 7
4 6 9 1 5 9 5 1 7 1
9
9 10
13 14
18 19
14 15
18 19
22 23
19 20
19 20
20 21
Hint
Sample 1 Explanation
Line 1:
Line 2: ,
Line 3: ,
Line 4: ,
Line 5: ,
Constraints
This problem uses bundled testdata.
- Subtask 1 (10 pts): .
- Subtask 2 (20 pts): .
- Subtask 3 (20 pts): .
- Subtask 4 (40 pts): testdata is randomly generated.
- Subtask 5 (10 pts): no special properties.
For of the testdata, , .
Translated by ChatGPT 5