Description

題目 PDF 檔在這裡

你真的很可悲欸 比我還可悲那種

— keaucucal, 建電一五學術長

kea 鄙視一切放閃行為,但身為單身漢的 kea 內心其實也相當羨慕有對象可以放閃,於是他決定踏上相親之路。

已知有 $n$ 個相親對象,每個對象都會給他一個日期 $d$,在那天前 (不含當天) 都可以接受約出來相親,否則逾期就去找別人了。

對於每個相親對象,kea 會根據自己有多喜歡她/他,評估出一個幸福指數 $r$,代表的是跟他相親,kea 會多幸福,因為 kea 平時沒人約,所以有無限天可以拿來相親。

kea 想要盡可能的幸福,也就是希望能獲得越多幸福指數越好。但他不是時間管理大師,一天只能跟一個人相親,

請問最大幸福指數是多少呢 ?

Input Format

第一行包含一個正整數 $n$ ($1 \leq n \leq 2 \cdot 105$) "--- 有幾個相親對象。

接下來有 $n$ 行,每行包含兩個正整數 $d_i, r_i$ "--- 相親期限與幸福指數。

Output Format

輸出一個正整數:能獲得的最大幸福指數。

Sample Input 1

5
2 70
1 30
1 50
2 80
1 10

Sample Output 1

150

Hints

對於範例測資:

第一天和第一個對象相親,獲得 $70$ 點幸福指數,第二天與第四個對象相親,獲得 $80$ 點幸福指數,總共 $70 + 80 = 150$ 點幸福指數

Problem Source

TopCoder

User's AC Ratio

100.0% (2/2)

Tags

Problem Setter

Created by keaucucal

Subtasks

No. Testdata Range Constraints Score
1 0 範例測資 2
2 1~7 $\forall i, j \ (1 \leq i \lt j \leq n) \implies d_i \neq d_j$ 8
3 8~14 $\forall i, j \ (1 \leq i \lt j \leq n) \implies r_i = r_j$ 12
4 15~21 $\forall i, j\ (1 \leq i,j \leq n) \quad d_i \lt d_j \implies r_i \gt r_j$ 18
5 0~30 無其他限制 60

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Memory Limit (RSS, KiB) Output Limit (KiB) Subtasks
0 1000 262144 262144 65536 1 5
1 1000 262144 262144 65536 2 5
2 1000 262144 262144 65536 2 5
3 1000 262144 262144 65536 2 5
4 1000 262144 262144 65536 2 5
5 1000 262144 262144 65536 2 5
6 1000 262144 262144 65536 2 5
7 1000 262144 262144 65536 2 5
8 1000 262144 262144 65536 3 5
9 1000 262144 262144 65536 3 5
10 1000 262144 262144 65536 3 5
11 1000 262144 262144 65536 3 5
12 1000 262144 262144 65536 3 5
13 1000 262144 262144 65536 3 5
14 1000 262144 262144 65536 3 5
15 1000 262144 262144 65536 4 5
16 1000 262144 262144 65536 4 5
17 1000 262144 262144 65536 4 5
18 1000 262144 262144 65536 4 5
19 1000 262144 262144 65536 4 5
20 1000 262144 262144 65536 4 5
21 1000 262144 262144 65536 4 5
22 1000 262144 262144 65536 5
23 1000 262144 262144 65536 5
24 1000 262144 262144 65536 5
25 1000 262144 262144 65536 5
26 1000 262144 262144 65536 5
27 1000 262144 262144 65536 5
28 1000 262144 262144 65536 5
29 1000 262144 262144 65536 5
30 1000 262144 262144 65536 5