Precarious Stacks

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

요약
축에 나란한 정사각형을 차례로 떨어뜨려 땅이나 먼저 놓인 정사각형 위에 얹고, 매번 구조물의 최대 높이를 구한다.
난이도

어려움10점 중 8점

유형
세그먼트 트리, 이분 탐색, 배열, 정렬
정답자
아직 제출이 없습니다

문제

It’s been difficult finding a job in the tech industry lately. You managed to land a job working for a construction company, but some of the tasks being assigned to you have you wondering whether the engineers have ever heard of gravity. Anyway, in the latest task, you are asked to evaluate the following model of a construction project.

The model is built by dropping axis-aligned squares, each with a specific xx coordinate and size, towards the ground (which is defined by the line y=0y=0). Each square will move downwards until its bottom face hits the ground or some other square. Once a square lands, it is securely fastened in place, so even if two squares are off balance, they will not fall over.

Given the list of squares to place and the order to place them in, determine the maximum yy coordinate reached by the structure after each square is placed.

입력

The first line of input contains an integer NN (1≤N≤1051 \le N \le 10^5) indicating how many squares there are in the model. The next NN lines describe the squares in the ordered they are to be dropped. Line ii contains two integers x_ix\_ i (0≤x_i≤1090 \le x\_ i \le 10^9) and s_is\_ i (1≤s_i≤1091 \le s\_ i \le 10^9), indicating the xx coordinate of the leftmost edge of square ii and the size of square ii, respectively.

출력

Output NN lines, with line ii containing the yy coordinate of the highest point that is reached by the structure after squares 1,…,i1,\dots ,i have been dropped.

예제4

  1. 예제 1

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

    입력
    5
    0 1
    0 10
    9 1
    0 10
    9 10
    
    예상 출력
    1
    11
    12
    22
    32
    
  3. 예제 3

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

    입력
    7
    0 5
    1 4
    2 3
    3 2
    4 1
    0 2
    0 5
    
    예상 출력
    5
    9
    12
    14
    15
    15
    20