Under construction

Still being built. Things may change

Precarious Stacks

Time limit4sMemory limit1024 MB

Summary
Given N squares dropped in order, each landing on the ground or on earlier squares, report the highest y coordinate after each drop.
Level

Medium5 of 10

Topics
Segment tree, Sorting
Solved
No attempts yet

Problem

It has been difficult to find a job in the tech industry lately. You landed a job at a construction company, but some of the tasks assigned to you make you wonder whether the engineers have ever heard of gravity. In the latest task, you must evaluate a model of a construction project.

The model is built by dropping axis-aligned squares toward the ground, which is the line y=0y=0. Each square has a fixed xx coordinate and size. A square moves downward until its bottom face touches the ground or another square. Once a square lands, it is fastened in place, so even if two squares are off balance, they do not fall over.

Given the squares and the order in which to drop them, find the maximum yy coordinate that the structure reaches after each square is placed.

Input

The first line contains an integer NN (1≤N≤1051 \le N \le 10^5), the number of squares. Each of the next NN lines describes a square in the order it is dropped. Line ii contains two integers xix_i (0≤xi≤1090 \le x_i \le 10^9) and sis_i (1≤si≤1091 \le s_i \le 10^9), the xx coordinate of the left edge of square ii and its size.

Output

Print NN lines. Line ii contains the highest yy coordinate reached by the structure after squares 1,…,i1,\dots,i have been dropped.

Examples4

  1. Example 1

    Input
    3
    0 1
    0 2
    0 3
    
    Expected output
    1
    3
    6
    
  2. Example 2

    Input
    5
    0 1
    0 10
    9 1
    0 10
    9 10
    
    Expected output
    1
    11
    12
    22
    32
    
  3. Example 3

    Input
    3
    0 1
    1 1
    2 1
    
    Expected output
    1
    1
    1
    
  4. Example 4

    Input
    7
    0 5
    1 4
    2 3
    3 2
    4 1
    0 2
    0 5
    
    Expected output
    5
    9
    12
    14
    15
    15
    20