#P8902. [USACO22DEC] Range Reconstruction S

    ID: 4937 远端评测题 2000ms 256MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>USACO2022Special Judge构造

[USACO22DEC] Range Reconstruction S

Problem Description

Bessie has an array a1,⋯ ,aNa_1, \cdots, a_N, where 1≤N≤3001 \le N \le 300 and for all ii we have 0≤ai≤1090 \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 i≤ji \le j, Bessie tells you ri,j=max⁡a[i⋯j]−min⁡a[i⋯j]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 i≤ji \le j, ri,j=max⁡a[i⋯j]−min⁡a[i⋯j]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 i≤ji \le j, ri,j=max⁡a[i⋯j]−min⁡a[i⋯j]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=max⁡a[1⋯3]−min⁡a[1⋯3]=3−1=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,N≤1r_{1,N} \le 1.
  • Test points 6−86-8 satisfy that for all 1≤i<N1 \le i<N we have ri,i+1=1r_{i,i+1}=1.
  • Test points 9−149-14 have no additional constraints.

Translated by ChatGPT 5