CF1746G.Olympiad Training

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:256MB

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.

安东决定为信息学奥林匹克竞赛做准备。伊利亚为他准备了 nn 道题目供其求解。第 ii 道题仅能在前 did_{i} 天内提交解答。安东每天最多只能求解一道题。伊利亚将第 ii 道题的有用性估计为 rir_{i},并将所有题目分为三类主题,其中第 ii 道题所属的主题为 typeitype_{i}。

安东希望恰好求解 aa 道第一类主题的题目、bb 道第二类主题的题目以及 cc 道第三类主题的题目。请判断安东能否实现这一目标;若可以,请计算他所能获得的最大总有用性。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \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 (1≤n≤1051 \le n \le 10^5, 0≤a,b,c≤n0 \le a, b, c \le n).

The following nn lines contain three integers each — ri,typei,dir_i, type_i, d_i (0≤ri≤1090 \le r_i \le 10^{9}, 1≤typei≤31 \le type_i \le 3, 1≤di≤n1 \le d_i \le n).

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

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例的第一行包含四个整数 n,a,b,cn, a, b, c(1≤n≤1051 \le n \le 10^5,0≤a,b,c≤n0 \le a, b, c \le n)。

接下来的 nn 行每行包含三个整数 —— ri,typei,dir_i, type_i, d_i(0≤ri≤1090 \le r_i \le 10^{9},1≤typei≤31 \le type_i \le 3,1≤di≤n1 \le d_i \le n)。

所有测试用例中 nn 的总和不超过 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.

如果 Anton 无法达成目标,则针对每个测试用例输出 −1-1;否则,输出他将解决的任务的最大实用性。

输入输出样例

  • 输入#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.

在样例测试的第一个测试用例中,安东可以解决第 22 和第 44 个任务。

在样例测试的第二个测试用例中,无法满足安东的愿望。

在样例测试的第三个测试用例中,最优策略是解决第 22、33 和 44 个任务。

在样例测试的最后一个测试用例中,最优策略是解决第 11、22 和 44 个任务。

输入解题思路,AI测评打分。不知道怎么写?

首页