Logo
(追記) (追記ここまで)

21077번 - Insects 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 256 MB144218.182%

문제

MianKing is playing a game. In this game, he has $n$ insects, and each insect has two integer attributes: type and level. The type and level of the $i$-th insect are $\mathit{type}_i$ and $\mathit{level}_i,ドル respectively.

Initially, each of these $n$ insects has a "seed" buff. When an insect with a "seed" buff is eliminated, let $L$ denote the highest level among the remaining insects (with the seed buff or not) of the same type as the eliminated insect. Then MianKing can choose an integer type $D$ from $[1, n]$ arbitrarily and add a new insect of type $D$ and level $L$. And this new insect does not have the "seed" buff.

Notice that if there are no other insects of the same type as the eliminated insect, no new insect can be added.

Now MianKing wants to maximize the total level of all insects on the field by eliminating some insects. The total level is the sum of levels of individual insects. You need to help him to calculate $\mathit{ans}_K,ドル the maximum total level that he can get by eliminating at most $K$ insects.

입력

The first line has one integer $n$ (1ドル \leq n \leq 10^5$).

Then there are $n$ lines, where the $i$-th line contains two integers $\mathit{type}_i$ and $\mathit{level}_i$ (1ドル \leq \mathit{type}_i \leq n,ドル 1ドル \leq \mathit{level}_i \leq 10^7$).

출력

Output $n$ lines, such that the $i$-th line has one integer $\mathit{ans}_i$.

제한

예제 입력 1

4
1 5
1 6
2 2
3 1

예제 출력 1

15
20
24
24

예제 입력 2

6
1 1
2 2
3 3
4 4
5 5
5 5

예제 출력 2

20
24
27
29
30
30

예제 입력 3

4
1 1
2 2
3 3
4 4

예제 출력 3

10
10
10
10

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2021 > Day 4: PKU Contest 1, ICPC Camp Day 2 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /