CF1746G Olympiad Training

题目描述

/* 安东决定为信息学奥赛做准备。伊利亚准备了几个任务让他去解决,且只能在前 $d_i$ 天完成第 $i$ 个任务。安东一天最多只能完成一项任务。伊利亚提供的第 $i$ 个任务价值为 $r_i$ ,并将任务分为三个主题,第 $i$ 个任务的主题是$type_i$。安东想要解决第一个主题的 $a$ 个任务,第二个主题的 $b$ 个任务,第三个主题的 $c$ 个任务。 请你帮安东得出是否能够这样做,如果可以,计算他可以解决的任务的最大价值之和。

输入格式

第一行,一个整数 $t(1 \leq t \leq 10^4)$ 表示测试数据个数。 对于每个数据,第一行四个整数 $n(1 \leq n \leq 10^5)$, $a$, $b$, $c(0 \leq a,b,c \leq n)$ ,接下来的 $n$ 行每行都包含三个整数 $r_i$ , $type_i$ , $d_i(0\leq r_i \leq 10^9 , 1 \leq type_i \leq 3 , 1 \leq d_i \leq n) $ 。 $ \sum{n} \leq 10^5 $

输出格式

对于每个测试用例,如果安东不能达到他的目标,打印 ```-1``` ;否则,打印他将解决的任务的最大有用性。 */

说明/提示

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 $ .