CF1746G.Olympiad Training
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Anton decided to get ready for an Olympiad in Informatics. Ilya prepared n tasks for him to solve. It is possible to submit the solution for the i -th task in the first di days only. Anton cannot solve more than one task a day. Ilya estimated the usefulness of the i -th tasks as ri and divided the tasks into three topics, the topic of the i -th task is typei .
Anton wants to solve exactly a tasks on the first topic, b tasks on the second topic and c tasks on the third topic. Tell Anton if it is possible to do so, and if it is, calculate the maximum total usefulness of the tasks he may solve.
输入格式
The first line of input contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains four integers n,a,b,c ( 1≤n≤105 , 0≤a,b,c≤n ).
The following n lines contain three integers each — ri,typei,di ( 0≤ri≤109 , 1≤typei≤3 , 1≤di≤n ).
The sum of n over all test cases does not exceed 105 .
输出格式
For each test case print −1 if Anton cannot reach his goal; otherwise, print the maximum usefulness of the tasks he will solve.
输入输出样例
输入#1
4 4 1 1 0 1 2 1 1 1 1 0 1 2 1 2 2 3 1 1 1 1 1 2 7 2 1 9 3 2 4 2 1 0 100 2 1 5 2 3 7 1 2 5 1 2 5 1 1 1 10 3 1 9 2 3 20 1 1 16 1 4 1 3 4
输出#1
2 -1 17 35
说明/提示
In the first test case from the sample test Anton can solve tasks 2 and 4 .
In the second test case from the sample test it is impossible to fulfill Anton's wish.
In the third test case from the sample test it is optimal to solve tasks 2 , 3 and 4 .
In the last test case from the sample test it is optimal to solve tasks 1 , 2 and 4 .