#P8963. 「WHOI-4」加减法构造

「WHOI-4」加减法构造

Problem Description

Little W gives you an integer array xx of length nn. You need to construct an integer array yy of length nn, and satisfy:

  1. 1i,j,i+jn,yi+j=yi+yj+k\forall 1\le i,j,i+j\le n,y_{i+j}=y_i+y_j+k, where kk is an integer that you must choose.
  2. Minimize d(x,y)=i=1nxiyid(x,y)=\sum\limits_{i=1}^n|x_i-y_i|.
  3. VyiV-V\le y_i\le V, where VV is a number given in the input.

Input Format

The first line contains two integers n,Vn,V.

The next line contains nn integers; the ii-th integer represents xix_i.

Output Format

The first line contains two integers k,dk,d, representing the value you choose and your answer.

The next line contains nn integers; the ii-th integer represents yiy_i.

It is guaranteed that the minimum value of dd fits in long long.

5 10
2 3 8 5 4
-1 6
2 3 4 5 6
7 100
11 45 14 19 19 8 10
-17 51
16 15 14 13 12 11 10

Hint

Constraints

  • Subtask 1 (2020 pts): n10n\le10, V10V\le10, xi10|x_i|\le10.
  • Subtask 2 (2020 pts): n100n\le100, xi100|x_i|\le100, V1000V\le1000.
  • Subtask 3 (2020 pts): n106n\le10^6, xi106|x_i|\le10^6, V=1012V=10^{12}.
  • Subtask 4 (2020 pts): n107n\le10^7, xi107|x_i|\le10^7, V107V\le10^7.
  • Subtask 5 (2020 pts): n107n\le10^7, xi107|x_i|\le10^7, V1012V\le 10^{12}.

For all testdata, it is guaranteed that 1n1071\le n\le 10^7, xi107|x_i|\le10^7, 1V10121\le V\le10^{12}.

Notes about the Special Judge

For each test point:

If your output format is incorrect, you will get 00 points.

If any number you output is not in the range [V,V][-V,V], you will get 00 points.

If your sequence yy does not match the kk you output, you will get 00 points.

If your sequence yy does not match the dd you output, you will get 00 points.

Otherwise, the score you get for this test point is max{0,min{100,1010010000dd}}\max\{0,\min\{100,10100-\frac{10000d}{d'}\}\} percent of the total score for this test point, where dd' is the dd value of the best answer.

Translated by ChatGPT 5