#5106. Problem 3. Range Reconstruction
Problem 3. Range Reconstruction
Problem 3. Range Reconstruction
USACO 2022 December Contest, Silver
Bessie has an array , where and for all . She won't tell you itself, but she will tell you the range of each subarray of . That is, for each pair of indices , Bessie tells you . Given these values of , please construct an array that could have been Bessie's original array. The values in your array should be in the range .
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains .
Another lines follow. The th of these lines contains the integers .
It is guaranteed that there is some array with values in the range such that for all , .
OUTPUT FORMAT (print output to the terminal / stdout):
Output one line containing integers in the range representing your array. They must satisfy for all .
SAMPLE INPUT:
3 0 2 2 0 1 0
SAMPLE OUTPUT:
1 3 2
For example, $r_{1, 3} = \max a[1\ldots 3] - \min a[1\ldots 3] = 3 - 1 = 2$.
SAMPLE INPUT:
3 0 1 1 0 0 0
SAMPLE OUTPUT:
0 1 1
This example satisfies the constraints for subtask 1.
SAMPLE INPUT:
4 0 1 2 2 0 1 1 0 1 0
SAMPLE OUTPUT:
1 2 3 2
This example satisfies the constraints for subtask 2.
SAMPLE INPUT:
4 0 1 1 2 0 0 2 0 2 0
SAMPLE OUTPUT:
1 2 2 0
SCORING: Test 5 satisfies .Tests 6-8 satisfy for all . Tests 9-14 satisfy no additional constraints.
Problem credits: Danny Mittal