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 nn ingredients, each with a certain weight. Big Eater can split these nn ingredients into any number of contiguous segments, and then pair each segment with a staple food of weight LL. 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 LL). 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 ii 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 nn and LL, meaning there are nn ingredients and the weight of each staple food is LL.

The second line contains nn integers, where the ii-th integer represents the weight of the ii-th ingredient aia_i.

Output Format

Output a total of nn lines.

The first line contains one integer, the minimum disharmony for the meal made from the first 11 dish.

On the ii-th line, output two integers: the minimum and second minimum disharmony for the meal made from the first ii 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: 4=(35)24=(3-5)^2
Line 2: 5=(35)2+(65)25=(3-5)^2+(6-5)^2, 16=(3+65)216=(3+6-5)^2
Line 3: 13=(35)2+(6+25)213=(3-5)^2+(6+2-5)^2, 14=(35)2+(65)2+(25)214=(3-5)^2+(6-5)^2+(2-5)^2
Line 4: 6=(35)2+(65)2+(2+45)26=(3-5)^2+(6-5)^2+(2+4-5)^2, 14=(35)2+(6+25)2+(45)214=(3-5)^2+(6+2-5)^2+(4-5)^2
Line 5: 15=(35)2+(65)2+(2+45)2+(85)215=(3-5)^2+(6-5)^2+(2+4-5)^2+(8-5)^2, 23=(35)2+(6+25)2+(45)2+(85)223=(3-5)^2+(6+2-5)^2+(4-5)^2+(8-5)^2

Constraints

This problem uses bundled testdata.

  • Subtask 1 (10 pts): 1n101 \le n \le 10.
  • Subtask 2 (20 pts): 1n2001 \le n \le 200.
  • Subtask 3 (20 pts): 1n30001 \le n \le 3000.
  • Subtask 4 (40 pts): testdata is randomly generated.
  • Subtask 5 (10 pts): no special properties.

For 100%100\% of the testdata, 1n2×1051 \le n \le 2 \times 10^5, 1L,ai1041 \le L, a_i \le 10^4.

Translated by ChatGPT 5