COCI '12 Contest 2 #4 Popust

View as PDF

Submit solution


Points: 10 (partial)
Time limit: 2.0s
Memory limit: 32M

Problem type

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.

Mirko 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 and 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 Specification

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 (0 \le A_i, B_i \le 1\,000\,000\,000), the prices for meal i as described above.

Output Specification

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

Sample Input 1

3
10 5
9 3
10 5

Sample Output 1

9
13
18

Explanation for Sample Output 1

k = 1: Mirko pays A_2 = 9 for the starting meal 2.

k = 2: Mirko pays A_1 = 10 for the starting meal 1, then B_2 = 3 for meal 2.

k = 3: Mirko pays A_1 = 10 for the starting meal 1, then B_2 = 3 for meal 2, and finally B_3 = 5 for meal 3.

Sample Input 2

2
100 1
1 100

Sample Output 2

1
2

Sample Input 3

5
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000

Sample Output 3

1000000000
2000000000
3000000000
4000000000
5000000000

Comments

There are no comments at the moment.