All problems

Problem 700

Falling Squares

Hard · 30 pts · Array, Segment Tree, Ordered Set

Problem

Squares are dropped one at a time onto the x-axis. Square i has its left edge at LEFT[i] and side length SIDE[i], so it covers x from LEFT[i] to LEFT[i] + SIDE[i]. It falls straight down until it lands on the ground or on top of an earlier square that it overlaps by a positive length (just touching at a corner or an edge does not count), and then stays there. After each drop, print the height of the tallest stack so far. With N up to 1000, comparing each new square with all earlier ones is fast enough.

Input

The first line contains N. Each of the next N lines contains LEFT[i] and SIDE[i].

Output

Print N integers separated by spaces: the tallest height after each drop.

Constraints

1 <= N <= 1000; 1 <= LEFT[i] <= 10^8; 1 <= SIDE[i] <= 10^6

Example input

3
1 2
2 3
6 1

Example output

2 5 5

Explanation

Square (1,2) lands on the ground with top at 2. Square (2,3) overlaps it on x from 2 to 3, so it lands at height 2 and reaches 5. Square (6,1) touches nothing and lands at 1. The tallest heights are 2 5 5.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Sum of Distances in Tree Next: Check if Array Is Sorted and Rotated