#P1787H. Codeforces Scoreboard
Codeforces Scoreboard
No submission language available for this problem.
Description
You are participating in a Codeforces Round with problems.
You spend exactly one minute to solve each problem, the time it takes to submit a problem can be ignored. You can only solve at most one problem at any time. The contest starts at time , so you can make your first submission at any time minutes. Whenever you submit a problem, it is always accepted.
The scoring of the -th problem can be represented by three integers , , and . If you solve it at time minutes, you get points.
Your task is to choose an order to solve all these problems to get the maximum possible score. You can assume the contest is long enough to solve all problems.
Each test contains multiple test cases. The first line contains an integer () — the number of test cases.
The first line of each test case contains one integer () — the number of problems.
The lines follow, the -th of them contains three integers , , (; ), denoting that you get the score of if you solve the -th task at time minutes.
It's guaranteed that the sum of does not exceed .
For each test case, print a line containing a single integer — the maximum score you can get.
Input
Each test contains multiple test cases. The first line contains an integer () — the number of test cases.
The first line of each test case contains one integer () — the number of problems.
The lines follow, the -th of them contains three integers , , (; ), denoting that you get the score of if you solve the -th task at time minutes.
It's guaranteed that the sum of does not exceed .
Output
For each test case, print a line containing a single integer — the maximum score you can get.
Note
In the second test case, the points for all problems at each minute are listed below.
Time | ||||||
Problem | ||||||
Problem | ||||||
Problem | ||||||
Problem | ||||||
Problem | ||||||
Problem |
The points displayed in red denote one of the optimal orders with the score .