CF1772G.Gaining Rating

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp is playing chess on one popular website. He has nn opponents he can play with. The ii-th opponent has rating equal to aia_i. Monocarp's initial rating is xx. Monocarp wants to raise his rating to the value yy (y>xy \gt x).

When Monocarp is playing against one of the opponents, he will win if his current rating is bigger or equal to the opponent's rating. If Monocarp wins, his rating is increased by 11, otherwise it is decreased by 11. The rating of his opponent does not change.

Monocarp wants to gain rating yy playing as few games as possible. But he can't just grind it, playing against weak opponents. The website has a rule that you should play against all opponents as evenly as possible. Speaking formally, if Monocarp wants to play against an opponent ii, there should be no other opponent jj such that Monocarp has played more games against ii than against jj.

Calculate the minimum possible number of games Monocarp needs to gain rating yy or say it's impossible. Note that ratings of Monocarp's opponents don't change, while Monocarp's rating does change.

Monocarp 正在某知名网站上玩国际象棋。他有 nn 个可对战的对手,其中第 ii 个对手的等级分为 aia_i。Monocarp 的初始等级分为 xx,他希望将自己的等级分提升至 yy(其中 y>xy > x)。

当 Monocarp 与某位对手对战时,若他当前的等级分大于或等于该对手的等级分,则他获胜;否则失败。若 Monocarp 获胜,他的等级分增加 11;若失败,则等级分减少 11。对手的等级分始终保持不变。

Monocarp 希望以最少的对局数达到等级分 yy。但他不能只反复挑战弱对手“刷分”。该网站有一条规则:玩家必须尽可能均匀地与所有对手对战。形式化地说,若 Monocarp 想要与对手 ii 进行一局对战,则不能存在另一对手 jj,使得 Monocarp 已与 ii 对战的局数多于已与 jj 对战的局数。

请计算 Monocarp 达到等级分 yy 所需的最少对局数;若不可能达成,请说明其不可能性。注意:Monocarp 各对手的等级分恒定不变,而 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, xx and yy (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤x<y≤10121 \le x \lt y \le 10^{12}) — the number of Monocarp's opponents, his initial and desired ratings.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤10121 \le a_i \le 10^{12}) — ratings of Monocarp's opponents.

Additional constraint on the input: the total sum of nn over all tt test cases doesn't exceed 2⋅1052 \cdot 10^5.

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

每个测试用例的第一行包含三个整数 nn、xx 和 yy(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤x<y≤10121 \le x \lt y \le 10^{12})—— 分别表示 Monocarp 的对手数量、他的初始评分和目标评分。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤10121 \le a_i \le 10^{12})—— 表示 Monocarp 各对手的评分。

输入的额外约束:所有 tt 个测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, print a single integer — the minimum number of games Monocarp needs to play to gain rating yy, or −1-1 if it's impossible.

对于每个测试用例,输出一个整数——Monocarp 为获得评分 yy 所需进行的最少比赛场数;若不可能实现,则输出 −1-1。

输入输出样例

  • 输入#1

    3
    7 2 10
    3 1 9 2 5 20 8
    7 1 10
    3 1 9 2 5 20 8
    5 10 12
    100 1 200 11 300

    输出#1

    20
    -1
    2

说明/提示

In the first test case, Monocarp can use the following strategy:

  1. Monocarp plays against the 22-nd opponent to increase rating (2→32 \to 3);
  2. Monocarp plays against the 11-st opponent to increase rating (3→43 \to 4);
  3. Monocarp plays against the 44-th opponent to increase rating (4→54 \to 5);
  4. Monocarp plays against the 55-th opponent to increase rating (5→65 \to 6);
  5. Now Monocarp have to play with remaining three opponents. So, he will lose 33 times and get rating 33 (6→5→4→36 \to 5 \to 4 \to 3);
  6. After that, Monocarp will repeat steps 1-5 again. After 1414 games, he has played twice with each opponent and get final rating 44.
  7. Monocarp plays against the 11-st opponent to increase rating (4→54 \to 5);
  8. Monocarp plays against the 22-nd opponent to increase rating (5→65 \to 6);
  9. Monocarp plays against the 44-th opponent to increase rating (6→76 \to 7);
  10. Monocarp plays against the 55-th opponent to increase rating (7→87 \to 8);
  11. Monocarp plays against the 77-th opponent to increase rating (8→98 \to 9);
  12. Monocarp plays against the 33-rd opponent to increase rating (9→109 \to 10);

In total, Monocarp, played twice against the 66-th opponent and three times against other opponents and got rating 1010 in 14+6=2014 + 6 = 20 games.

In the second test case, it can be proven that whichever games Monocarp plays, he can't get his rating higher than 44.

在第一个测试用例中,Monocarp 可采用如下策略:

  1. Monocarp 与第 22 位对手对战以提升评分(2→32 \to 3);
  2. Monocarp 与第 11 位对手对战以提升评分(3→43 \to 4);
  3. Monocarp 与第 44 位对手对战以提升评分(4→54 \to 5);
  4. Monocarp 与第 55 位对手对战以提升评分(5→65 \to 6);
  5. 此时 Monocarp 需与剩余三位对手对战。因此,他将连输 33 场,评分降至 33(6→5→4→36 \to 5 \to 4 \to 3);
  6. 此后,Monocarp 将再次重复步骤 1–5。经过 1414 场比赛,他已与每位对手各交手两次,最终评分为 44;
  7. Monocarp 与第 11 位对手对战以提升评分(4→54 \to 5);
  8. Monocarp 与第 22 位对手对战以提升评分(5→65 \to 6);
  9. Monocarp 与第 44 位对手对战以提升评分(6→76 \to 7);
  10. Monocarp 与第 55 位对手对战以提升评分(7→87 \to 8);
  11. Monocarp 与第 77 位对手对战以提升评分(8→98 \to 9);
  12. Monocarp 与第 33 位对手对战以提升评分(9→109 \to 10)。

总计,Monocarp 与第 66 位对手交手两次,与其他每位对手各交手三次,在 14+6=2014 + 6 = 20 场比赛中获得最终评分 1010。

在第二个测试用例中,可以证明:无论 Monocarp 如何安排对战顺序,其评分均无法超过 44。

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

首页