| ICPC Masters Mexico 2026 |
|---|
| Finished |
The jury has collected $$$N$$$ candidate problems, and has only a few weeks to turn them into a contest. Problem $$$i$$$ would add $$$g_i$$$ points of quality to the set, a non-negative integer.
Preparing a problem is not only writing the statement. It also needs tests, a validator, a checker and at least two independent solutions, so one problem takes a full working day of the whole jury.
Every candidate problem also has an author who is available only for a limited time. Problem $$$i$$$ must be finished on day $$$d_i$$$ at the latest, where $$$d_i$$$ is a positive integer.
The jury works on days $$$1,2,3,\ldots$$$ and can prepare at most one problem per day, and no problem can be prepared twice. If problem $$$i$$$ is prepared on day $$$t$$$, then $$$t \le d_i$$$ must hold.
The jury may also drop any candidate problem. Find the maximum total quality of the final problem set.
The first line contains one integer $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of candidate problems.
Each of the next $$$N$$$ lines contains two integers $$$g_i$$$ and $$$d_i$$$ ($$$0 \le g_i \le 10^9$$$, $$$1 \le d_i \le 10^9$$$) — the quality and the last allowed day of problem $$$i$$$.
Print one integer — the maximum total quality.
520 12 110 2100 28 3
128
41000000000 10000000001000000000 10000000001000000000 10000000001000000000 1000000000
4000000000
45 16 14 210 2
16
In the first example, the problems with quality $$$20$$$, $$$100$$$, and $$$8$$$ can be prepared on days $$$1$$$, $$$2$$$, and $$$3$$$, respectively.
In the third example, only one of the two problems with last allowed day $$$1$$$ can be prepared. Choosing the problems with quality $$$6$$$ and $$$10$$$ is optimal.
| Name |
|---|


