CF1746G.Olympiad Training

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Anton decided to get ready for an Olympiad in Informatics. Ilya prepared nn tasks for him to solve. It is possible to submit the solution for the ii -th task in the first did_{i} days only. Anton cannot solve more than one task a day. Ilya estimated the usefulness of the ii -th tasks as rir_{i} and divided the tasks into three topics, the topic of the ii -th task is typeitype_{i} .

Anton wants to solve exactly aa tasks on the first topic, bb tasks on the second topic and cc 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 tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains four integers n,a,b,cn, a, b, c ( 1n1051 \le n \le 10^5 , 0a,b,cn0 \le a, b, c \le n ).

The following nn lines contain three integers each — ri,typei,dir_i, type_i, d_i ( 0ri1090 \le r_i \le 10^{9} , 1typei31 \le type_i \le 3 , 1din1 \le d_i \le n ).

The sum of nn over all test cases does not exceed 10510^5 .

输出格式

For each test case print 1-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 22 and 44 .

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 22 , 33 and 44 .

In the last test case from the sample test it is optimal to solve tasks 11 , 22 and 44 .

首页