1974: [USACO 2022 December Contest Silver] Problem 3. Range Reconstruction

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:13 解决:0

题目描述

Bessie has an array a1,,aN, where 1N300 and 0ai109 for all i. She won't tell you a itself, but she will tell you the range of each subarray of a. That is, for each pair of indices ij, Bessie tells you ri,j=maxa[ij]mina[ij]. Given these values of r, please construct an array that could have been Bessie's original array. The values in your array should be in the range [109,109].

输入

The first line contains N.

Another N lines follow. The ith of these lines contains the integers ri,i,ri,i+1,,ri,N.

It is guaranteed that there is some array a with values in the range [0,109] such that for all ijri,j=maxa[ij]mina[ij].

输出

Output one line containing N integers b1,b2,,bN in the range[109,109] representing your array. They must satisfy ri,j=maxb[ij]minb[ij] for all ij.

样例输入

3
0 2 2
0 1
0

样例输出

1 3 2

提示

For example, r1,3=maxa[13]mina[13]=31=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 r1,N1.
  • Tests 6-8 satisfy ri,i+1=1 for all 1i<N.
  • Tests 9-14 satisfy no additional constraints.

来源/分类