아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Range Reconstruction

시간 제한2초메모리 제한1024 MB

요약
모든 부분 배열의 최댓값과 최솟값의 차이가 주어질 때, 그 값들을 그대로 만족하는 배열을 하나 복원한다.
난이도

보통10점 중 7점

유형
동적 계획법, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Bessie has an array a_1,…,a_Na\_1, \ldots, a\_N, where 1≤N≤3001 \leq N \leq 300 and 0≤a_i≤1090 \leq a\_i \leq 10^9 for all ii. She won't tell you aa itself, but she will tell you the range of each subarray of aa. That is, for each pair of indices i≤ji \leq j, Bessie tells you r_i,j=max⁡a\[i…j]−min⁡a\[i…j]r\_{i, j} = \max a\[i\ldots j] - \min a\[i\ldots j]. Given these values of rr, please construct an array that could have been Bessie's original array. The values in your array should be in the range \[−109,109]\[-10^9, 10^9].

입력

The first line contains NN.

Another NN lines follow. The iith of these lines contains the integers r_i,i,r_i,i+1,…,r_i,Nr\_{i, i}, r\_{i, i + 1}, \ldots, r\_{i, N}.

It is guaranteed that there is some array aa with values in the range \[0,109]\[0, 10^9] such that for all i≤ji \leq j, r_i,j=max⁡a\[i…j]−min⁡a\[i…j]r\_{i, j} = \max a\[i\ldots j] - \min a\[i\ldots j].

출력

Output one line containing NN integers b_1,b_2,…,b_Nb\_1, b\_2, \ldots, b\_N in the range \[−109,109]\[-10^9, 10^9] representing your array. They must satisfy r_i,j=max⁡b\[i…j]−min⁡b\[i…j]r\_{i, j} = \max b\[i\ldots j] - \min b\[i\ldots j] for all i≤ji \leq j.

예제4

  1. 예제 1

    입력
    3
    0 2 2
    0 1
    0
    
    예상 출력
    1 3 2
    
  2. 예제 2

    입력
    3
    0 1 1
    0 0
    0
    
    예상 출력
    0 1 1
    
  3. 예제 3

    입력
    4
    0 1 2 2
    0 1 1
    0 1
    0
    
    예상 출력
    1 2 3 2
    
  4. 예제 4

    입력
    4
    0 1 1 2
    0 0 2
    0 2
    0
    
    예상 출력
    1 2 2 0