Preparando MOJI
You have $$$n$$$ lamps, numbered by integers from $$$1$$$ to $$$n$$$. Each lamp $$$i$$$ has two integer parameters $$$a_i$$$ and $$$b_i$$$.
At each moment each lamp is in one of three states: it may be turned on, turned off, or broken.
Initially all lamps are turned off. In one operation you can select one lamp that is turned off and turn it on (you can't turn on broken lamps). You receive $$$b_i$$$ points for turning lamp $$$i$$$ on. The following happens after each performed operation:
Please note that broken lamps never count as turned on and that after a turned on lamp breaks, you still keep points received for turning it on.
You can perform an arbitrary number of operations.
Find the maximum number of points you can get.
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of lamps.
Each of the next $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i \le n, 1 \le b_i \le 10^9$$$) — parameters of the $$$i$$$-th lamp.
It is guaranteed that sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.
For each test case, output one integer — the maximum number of points you can get.
442 21 61 101 1353 43 12 53 23 361 23 41 43 43 52 311 1
15 14 20 1
In first test case $$$n = 4$$$. One of ways to get the maximum number of points is as follows:
Your receive $$$13 + 2 = 15$$$ points in total. It can be shown that this is the maximum number of points you can get, so the answer for the first test case is $$$15$$$.
In the second test case, one of the ways to get the maximum number of points is as follows:
You receive $$$2 + 5 + 4 + 3 = 14$$$ points in total. It can be shown that this is the maximum number of points you can get.
In the third test case, one of the ways to get the maximum number of points is as follows:
You receive $$$4 + 4 + 3 + 4 + 5 = 20$$$ points in total. It can be shown that this is the maximum number of points you can get.