#P8902. [USACO22DEC] Range Reconstruction S

[USACO22DEC] Range Reconstruction S

Description

Bessie has an array a1,,aNa_1, \cdots, a_N, where 1N3001 \le N \le 300 and for all ii we have 0ai1090 \le a_i \le 10^9. She will not tell you the array aa itself, but she will tell you the range of every subarray of aa. That is, for every pair of indices iji \le j, Bessie tells you ri,j=maxa[ij]mina[ij]r_{i,j}= \max a[i \cdots j]− \min a[i \cdots j]. Given these rr values, construct an array that could be Bessie's original array. The values in your array must be in the range [109,109][−10^9,10^9].

Input Format

The first line contains NN.

The next NN lines: line ii contains the integers ri,i,ri,i+1,,ri,Nr_{i,i},r_{i,i+1}, \cdots ,r_{i,N}.

It is guaranteed that there exists some array aa, with values in the range [0,109][0,10^9], such that for all iji \le j, ri,j=maxa[ij]mina[ij]r_{i,j}= \max a[i \cdots j]−\min a[i\cdots j].

Output Format

Output one line containing NN integers b1,b2,,bNb_1,b_2, \cdots ,b_N in the range [109,109][−10^9,10^9], representing your array. These numbers must satisfy that for all iji \le j, ri,j=maxa[ij]mina[ij]r_{i,j}= \max a[i \cdots j]−\min a[i\cdots j].

3
0 2 2
0 1
0
1 3 2
3
0 1 1
0 0
0
0 1 1
4
0 1 2 2
0 1 1
0 1
0
1 2 3 2
4
0 1 1 2
0 0 2
0 2
0
1 2 2 0

Hint

Sample 1 Explanation

For example, r1,3=maxa[13]mina[13]=31=2r_{1,3}=\max a[1 \cdots 3]−\min a[1\cdots 3]=3−1=2.

Sample 2 Explanation

This sample satisfies the constraints of subtask 1.

Sample 3 Explanation

This sample satisfies the constraints of subtask 2.

Properties of test points

  • Test point 55 satisfies r1,N1r_{1,N} \le 1.
  • Test points 686-8 satisfy that for all 1i<N1 \le i<N we have ri,i+1=1r_{i,i+1}=1.
  • Test points 9149-14 have no additional constraints.

Translated by ChatGPT 5