CF2182E.New Year's Gifts

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Monocarp has nn friends and decided to give a New Year's gift to each of them. He has also prepared mm boxes to place the gifts in; the beauty of the ii-th box is aia_i. Every box can contain at most one gift.

Monocarp wants to give a gift worth at least yiy_i coins to the ii-th friend. Additionally, he knows that the ii-th friend will be happy if at least one of the following conditions holds:

  • the gift is in a box with beauty at least xix_i;
  • the gift is worth at least ziz_i (zi>yiz_i \gt y_i).

Your task is to help Monocarp calculate the maximum possible number of friends he can make happy if he has kk coins. Note that Monocarp must purchase a gift for each friend, and the gift may not necessarily come in a box.

Monocarp 有 nn 位朋友,并决定给每位朋友赠送一份新年礼物。他还准备了 mm 个盒子来盛放这些礼物;第 ii 个盒子的美观度为 aia_i。每个盒子最多只能装一份礼物。

Monocarp 希望送给第 ii 位朋友的礼物价值至少为 yiy_i 枚金币。此外,他知道第 ii 位朋友会感到开心,当且仅当满足以下至少一个条件:

  • 礼物被放在美观度至少为 xix_i 的盒子中;
  • 礼物本身的价值至少为 ziz_i(其中 zi>yiz_i > y_i)。

你的任务是帮助 Monocarp 计算:在总预算为 kk 枚金币的前提下,他最多能让多少位朋友感到开心?注意,Monocarp 必须为每位朋友都购买一份礼物,且该礼物不一定非得装入盒子中。

输入格式

The first line 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 three integers nn, mm and kk (1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5; 1≤k≤10151 \le k \le 10^{15}).

The second line contains mm integers a1,a2,…,ama_1, a_2, \dots, a_m (1≤ai≤m1 \le a_i \le m).

Then nn lines follow; the ii-th of them contains three integers xix_i, yiy_i and ziz_i (1≤xi≤m1 \le x_i \le m; 1≤yi<zi≤1091 \le y_i \lt z_i \le 10^9).

Additional constraints on the input:

  • ∑i=1nyi≤k\sum\limits_{i=1}^{n} y_i \le k.
  • the sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5;
  • the sum of mm over all test cases doesn't exceed 2⋅1052 \cdot 10^5;

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

每个测试用例的第一行包含三个整数 nn、mm 和 kk(1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5;1≤k≤10151 \le k \le 10^{15})。

第二行包含 mm 个整数 a1,a2,…,ama_1, a_2, \dots, a_m(1≤ai≤m1 \le a_i \le m)。

随后是 nn 行;其中第 ii 行包含三个整数 xix_i、yiy_i 和 ziz_i(1≤xi≤m1 \le x_i \le m;1≤yi<zi≤1091 \le y_i \lt z_i \le 10^9)。

输入的额外约束条件:

  • ∑i=1nyi≤k\sum\limits_{i=1}^{n} y_i \le k;
  • 所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5;
  • 所有测试用例中 mm 的总和不超过 2⋅1052 \cdot 10^5;

输出格式

For each test case, print a single integer — the maximum possible number of friends Monocarp can make happy if he has kk coins.

对于每个测试用例,输出一个整数——即 Monocarp 拥有 kk 枚硬币时,最多能让多少位朋友开心。

输入输出样例

  • 输入#1

    3
    2 1 6
    1
    1 2 3
    1 2 7
    2 2 3
    1 1
    2 1 3
    2 1 5
    3 4 11
    1 2 2 1
    3 2 5
    4 4 6
    3 1 3

    输出#1

    2
    0
    2

说明/提示

In the first example, Monocarp can make both friends happy as follows: give the first friend a gift for 33 coins, and give the second friend a gift for 22 coins in a box with 11 beauty.

In the second example, Monocarp cannot make any of his friends happy, because he does not have enough money to buy a gift for ziz_i coins for even one of them; also, all the boxes have less beauty than any of the xix_i.

In the third example, Monocarp can make two friends (the 22-nd friend and the 33-rd friend) happy as follows: give the first friend a gift for 22 coins, and give the second friend a gift for 66 coins, and give the third friend a gift for 33 coins.

在第一个例子中,Monocarp 可以通过以下方式让两位朋友都开心:给第一位朋友赠送一个价值 33 枚硬币的礼物,给第二位朋友赠送一个装在美观度为 11 的礼盒中、价值 22 枚硬币的礼物。

在第二个例子中,Monocarp 无法让任何一位朋友开心,因为他甚至没有足够的钱为其中任意一位朋友购买价值 ziz_i 枚硬币的礼物;此外,所有礼盒的美观度均小于任意一个 xix_i。

在第三个例子中,Monocarp 可以让两位朋友(即第 22 位朋友和第 33 位朋友)开心,方法如下:给第一位朋友赠送一个价值 22 枚硬币的礼物,给第二位朋友赠送一个价值 66 枚硬币的礼物,给第三位朋友赠送一个价值 33 枚硬币的礼物。

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

首页