CF1783C.Yet Another Tournament

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are participating in Yet Another Tournament. There are n+1n + 1 participants: you and nn other opponents, numbered from 11 to nn.

Each two participants will play against each other exactly once. If the opponent ii plays against the opponent jj, he wins if and only if i>ji \gt j.

When the opponent ii plays against you, everything becomes a little bit complicated. In order to get a win against opponent ii, you need to prepare for the match for at least aia_i minutes — otherwise, you lose to that opponent.

You have mm minutes in total to prepare for matches, but you can prepare for only one match at one moment. In other words, if you want to win against opponents p1,p2,…,pkp_1, p_2, \dots, p_k, you need to spend ap1+ap2+⋯+apka_{p_1} + a_{p_2} + \dots + a_{p_k} minutes for preparation — and if this number is greater than mm, you cannot achieve a win against all of these opponents at the same time.

The final place of each contestant is equal to the number of contestants with strictly more wins ++ 11. For example, if 33 contestants have 55 wins each, 11 contestant has 33 wins and 22 contestants have 11 win each, then the first 33 participants will get the 11-st place, the fourth one gets the 44-th place and two last ones get the 55-th place.

Calculate the minimum possible place (lower is better) you can achieve if you can't prepare for the matches more than mm minutes in total.

你正在参加“又一场比赛”(Yet Another Tournament)。共有 n+1n + 1 名参赛者:你和其余 nn 名对手,编号从 11 到 nn。

每两名参赛者之间恰好进行一场比赛。当对手 ii 与对手 jj 比赛时,当且仅当 i>ji > j 时,对手 ii 获胜。

当你与对手 ii 比赛时,情况变得稍微复杂一些。为了战胜对手 ii,你必须至少为此场比赛准备 aia_i 分钟;否则,你将输给该对手。

你总共只有 mm 分钟可用于赛前准备,且同一时刻只能为一场比赛做准备。换言之,若你想战胜对手 p1,p2,…,pkp_1, p_2, \dots, p_k,则需花费 ap1+ap2+⋯+apka_{p_1} + a_{p_2} + \dots + a_{p_k} 分钟进行准备;若该总和超过 mm,则你无法同时战胜所有这些对手。

每位参赛者的最终名次等于“严格胜场数比他多的参赛者人数”加 11。例如,若有 33 名参赛者各胜 55 场,11 名参赛者胜 33 场,另有 22 名参赛者各胜 11 场,则前 33 名参赛者获得第 11 名,第 44 名参赛者获得第 44 名,最后 22 名参赛者均获得第 55 名。

在总计准备时间不超过 mm 分钟的前提下,求你能取得的最小可能名次(数值越小越好)。

输入格式

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 two integers nn and mm (1≤n≤5⋅1051 \le n \le 5 \cdot 10^5; 0≤m≤∑i=1nai0 \le m \le \sum\limits_{i=1}^{n}{a_i}) — the number of your opponents and the total time you have for preparation.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤10000 \le a_i \le 1000), where aia_i is the time you need to prepare in order to win against the ii-th opponent.

It's guaranteed that the total sum of nn over all test cases doesn't exceed 5⋅1055 \cdot 10^5.

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

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n≤5⋅1051 \le n \le 5 \cdot 10^5;0≤m≤∑i=1nai0 \le m \le \sum\limits_{i=1}^{n}{a_i})—— 你的对手数量以及你用于准备的总时间。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤10000 \le a_i \le 1000),其中 aia_i 表示你为战胜第 ii 个对手所需花费的准备时间。

保证所有测试用例中 nn 的总和不超过 5⋅1055 \cdot 10^5。

输出格式

For each test case, print the minimum possible place you can take if you can prepare for the matches no more than mm minutes in total.

对于每个测试用例,输出在总共最多准备 mm 分钟的情况下,你能获得的最小可能名次。

输入输出样例

  • 输入#1

    5
    4 401
    100 100 200 1
    3 2
    1 2 3
    5 0
    1 1 1 1 1
    4 0
    0 1 1 1
    4 4
    1 2 2 1

    输出#1

    1
    2
    6
    4
    1

说明/提示

In the first test case, you can prepare to all opponents, so you'll win 44 games and get the 11-st place, since all your opponents win no more than 33 games.

In the second test case, you can prepare against the second opponent and win. As a result, you'll have 11 win, opponent 11 — 11 win, opponent 22 — 11 win, opponent 33 — 33 wins. So, opponent 33 will take the 11-st place, and all other participants, including you, get the 22-nd place.

In the third test case, you have no time to prepare at all, so you'll lose all games. Since each opponent has at least 11 win, you'll take the last place (place 66).

In the fourth test case, you have no time to prepare, but you can still win against the first opponent. As a result, opponent 11 has no wins, you have 11 win and all others have at least 22 wins. So your place is 44.

在第一个测试用例中,你可以为所有对手做准备,因此你将赢得 44 场比赛并获得第 11 名,因为你的所有对手最多只赢得 33 场比赛。

在第二个测试用例中,你可以为第二位对手做准备并获胜。结果是:你有 11 场胜利,对手 11 有 11 场胜利,对手 22 有 11 场胜利,对手 33 有 33 场胜利。因此,对手 33 将获得第 11 名,其余所有参赛者(包括你)均获得第 22 名。

在第三个测试用例中,你完全没时间做准备,因此你将输掉所有比赛。由于每位对手至少有 11 场胜利,你将获得最后一名(即第 66 名)。

在第四个测试用例中,你没有时间做准备,但仍可战胜第一位对手。结果是:对手 11 没有胜场,你有 11 场胜利,而其他所有对手至少有 22 场胜利。因此,你的名次为第 44 名。

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

首页