#P8298. [COCI 2012/2013 #2] POPUST

[COCI 2012/2013 #2] POPUST

Background

The score for this problem follows the original COCI settings, with a full score of 120120.

Problem Description

Mirko is as hungry as a bear and finds a local restaurant. This restaurant offers NN meals and has an interesting pricing policy: each meal has two specified prices, AiA_i and BiB_i. The first dish Mirko orders only costs AA money, and all other dishes cost BB money.

Mirko cannot decide how many dishes to order. To make the decision easier, he asks you for help. For any k[1,N]k\in[1,N], find the minimum amount of money he needs to pay to order kk dishes. Mirko does not care which specific meals he orders, nor the order in which he orders them, but he will not order two identical dishes.

Input Format

The first line contains a positive integer N (2N5×105)N\ (2\le N\le 5\times 10^5), which is the number of dishes.

The next NN lines each contain two positive integers Ai,Bi (1Ai,Bi109)A_i,B_i\ (1\le A_i,B_i\le 10^9), as described in the statement.

Output Format

Output NN lines. The kk-th line should be the minimum amount of money needed to order kk distinct dishes.

3
10 5
9 3
10 5
9
13
18
2
100 1
1 100
1
2
5
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000
2000000000
3000000000
4000000000
5000000000

Hint

Explanation for Sample #1

  • k=1k=1: Mirko starts by ordering the 22-nd dish, with a total cost of A2=9A_2=9.

  • k=2k=2: Mirko starts by ordering the 11-st dish, then orders the 22-nd dish, with a total cost of A1+B2=13A_1+B_2=13.

  • k=3k=3: Mirko starts by ordering the 11-st dish, then orders dishes 2,32,3, with a total cost of A1+B2+B3=18A_1+B_2+B_3=18.

Translated by ChatGPT 5