#abc348g. G - Max (Sum - Max)

G - Max (Sum - Max)

Score: 650650 points

问题陈述

给定两个整数序列 AABB,它们的长度都是 NN。对于 k=1,2,,Nk = 1, 2, \ldots, N,解决以下问题:

  • 考虑在 11NN(包括 11NN)之间选择 kk 个不同的整数。设 SS 是所选整数的集合。找到 $\displaystyle (\sum_{i \in S} A_i) - \max_{i \in S} B_i$ 的最大值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given two integer sequences AA and BB of length NN. For k=1,2,,Nk = 1, 2, \ldots, N, solve the following problem:

  • Consider choosing kk distinct integers between 11 and NN, inclusive. Let SS be the set of chosen integers. Find the maximum value of $\displaystyle (\sum_{i \in S} A_i) - \max_{i \in S} B_i$.

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 109Ai109-10^9 \leq A_i \leq 10^9
  • 2×1014Bi2×1014-2 \times 10^{14} \leq B_i \leq 2 \times 10^{14}

Input

The input is given from Standard Input in the following format:

NN

A1A_1 B1B_1

A2A_2 B2B_2

\vdots

ANA_N BNB_N

Output

Print NN lines. The ii-th line should contain the answer to the problem for k=ik=i.

Sample Input 1

3
4 1
5 6
3 2

Sample Output 1

3
5
6

The following choices are optimal.

  • k=1k = 1: S={1}S = \{1\}
  • k=2k = 2: S={1,3}S = \{1, 3\}
  • k=3k = 3: S={1,2,3}S = \{1, 2, 3\}

Sample Input 2

2
0 1
0 1

Sample Output 2

-1
-1

Sample Input 3

6
9 7
2 4
7 1
-1000 0
3 4
8 5

Sample Output 3

6
10
17
20
22
-978