Problem list
Log in
#coci00243 · COCI 2012/2013 Contest 2

Popust

Gold I 2.0 s 32 MB

Mirko is hungry as a bear, scratch that, programmer and has stumbled upon a local restaurant. The restaurant offers N meals and has an interesting pricing policy: each meal i has two assigned prices, A_{i} and B_{i}. Mirko pays A only for the first ordered meal, while B prices apply for all other meals. Mikro can't decide how many meals to order. In order to make his decision easier, he has asked you to compute, for each k between 1 i N (inclusive), the minimum total price for k ordered meals. Mirko doesn't care which particular meals he orders or in which order he orders them, however he won't order the same meal twice. Order, order, order.

Input

The first line of input contains the positive integer N ($2 \le N \le 500,000$), the number of different meals offered by the restaurant. Each of the following N lines contains two positive integers, A_{i}and B_{i} ($1 \le A_{i}$, $B_{i} \le 1,000,000,000$), the prices for meal i as described above.

Output

Output must consist of N lines, where line k contains the minimum price for ordering exactly k different meals.

Example 1

Input
3
10 5
9 3
10 5
Output
9
13
18

Example 2

Input
2
100 1
1 100
Output
1
2

Example 3

Input
5
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
Output
1000000000
2000000000
3000000000
4000000000
5000000000

Clarification of the first example: k = 1: Mirko pays A2 = 9 for the starting meal 2. k = 2: Mirko pays A1 = 10 for the starting meal 1, then B2 = 3 for meal 2. k = 3: Mirko pays A1 = 10 for the starting meal 1, then B2 = 3 for meal 2, and finally B3 = 5 for meal 3.

Source
COCI 2012/2013 Contest 2
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code