CF1250G.Discarding Game
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Eulampius has created a game with the following rules:
- there are two players in the game: a human and a computer;
- the game lasts for no more than n rounds. Initially both players have 0 points. In the j-th round the human gains aj points, and the computer gains bj points. The points are gained simultaneously;
- the game ends when one of the players gets k or more points. This player loses the game. If both players get k or more points simultaneously, both lose;
- if both players have less than k points after n rounds, the game ends in a tie;
- after each round the human can push the "Reset" button. If the human had x points, and the computer had y points before the button is pushed (of course, x<k and y<k), then after the button is pushed the human will have x′=max(0,x−y) points, and the computer will have y′=max(0,y−x) points. E. g. the push of "Reset" button transforms the state (x=3,y=5) into the state (x′=0,y′=2), and the state (x=8,y=2) into the state (x′=6,y′=0).
Eulampius asked his friend Polycarpus to test the game. Polycarpus has quickly revealed that amounts of points gained by the human and the computer in each of n rounds are generated before the game and stored in a file. In other words, the pushes of the "Reset" button do not influence the values aj and bj, so sequences a and b are fixed and known in advance.
Polycarpus wants to make a plan for the game. He would like to win the game pushing the "Reset" button as few times as possible. Your task is to determine this minimal number of pushes or determine that Polycarpus cannot win.
尤兰皮乌斯设计了一个遵循以下规则的游戏:
- 游戏中有两名玩家:人类玩家和计算机;
- 游戏最多进行 n 轮。初始时,双方得分均为 0。在第 j 轮中,人类玩家获得 aj 分,计算机获得 bj 分;双方得分是同时增加的;
- 当任意一名玩家的累计得分达到 k 或以上时,游戏立即结束,该玩家判负;若双方同时达到 k 或以上分,则双方均判负;
- 若经过全部 n 轮后,双方得分均仍低于 k,则游戏以平局结束;
- 每轮结束后,人类玩家可按下“重置(Reset)”按钮。若按下按钮前人类得分为 x、计算机得分为 y(显然此时必有 x<k 且 y<k),则按下后人类得分变为 x′=max(0,x−y),计算机得分变为 y′=max(0,y−x)。例如:“重置”操作将状态 (x=3,y=5) 变为 (x′=0,y′=2),将状态 (x=8,y=2) 变为 (x′=6,y′=0)。
尤兰皮乌斯请他的朋友波利卡普斯测试该游戏。波利卡普斯很快发现:游戏中每轮人类与计算机所获分数 aj 和 bj(共 n 轮)是在游戏开始前即已生成并存于文件中的。换言之,“重置”按钮的按下不会影响后续各轮的 aj 和 bj 值,因此序列 a 和 b 是固定且预先已知的。
波利卡普斯希望为游戏制定一个策略:他希望获胜,且按下“重置”按钮的次数尽可能少。你的任务是求出这一最小按下次数;若波利卡普斯无法获胜,则需指出这一点。
输入格式
The first line of the input contains one integer t (1≤t≤10000) — the number of test cases. Then the test cases follow.
The first line of each test case contains two integers n and k (1≤n≤2⋅105, 2≤k≤109) — the maximum possible number of rounds in the game and the number of points, after reaching which a player loses, respectively.
The second line of each test case contains n integers a1,a2,…,an (1≤aj<k), where aj is the amount of points the human gains in the j-th round.
The third line of each test case contains n integers b1,b2,…,bn (1≤bj<k), where bj is the amount of points the computer gains in the j-th round.
The sum of n over all test cases in the input does not exceed 2⋅105.
输入的第一行包含一个整数 t(1≤t≤10000),表示测试用例的数量。随后是各测试用例。
每个测试用例的第一行包含两个整数 n 和 k(1≤n≤2⋅105,2≤k≤109),分别表示游戏中最多可能进行的轮数,以及玩家一旦达到该分数即判负的阈值。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤aj<k),其中 aj 表示人类玩家在第 j 轮中获得的分数。
每个测试用例的第三行包含 n 个整数 b1,b2,…,bn(1≤bj<k),其中 bj 表示电脑玩家在第 j 轮中获得的分数。
输入中所有测试用例的 n 值之和不超过 2⋅105。
输出格式
Print the answers for all test cases in the order they appear in the input.
If Polycarpus cannot win the game, then simply print one line "-1" (without quotes). In this case, you should not output anything else for that test case. Otherwise, the first line of the test case answer should contain one integer d — the minimum possible number of "Reset" button pushes, required to win the game. The next line should contain d distinct integers r1,r2,…,rd (1≤ri<n) — the numbers of rounds, at the end of which Polycarpus has to press the "Reset" button, in arbitrary order. If d=0 then either leave the second line of the test case answer empty, or do not print the second line at all.
If there are several possible solutions, print any of them.
按输入中测试用例出现的顺序输出所有测试用例的答案。
如果 Polycarpus 无法赢得游戏,则只需输出一行 -1(不带引号)。此时,该测试用例不应再输出任何其他内容。否则,该测试用例答案的第一行应包含一个整数 d —— 赢得游戏所需的最小“重置”按钮按下次数。第二行应包含 d 个互不相同的整数 r1,r2,…,rd(满足 1≤ri<n),表示 Polycarpus 必须在第 ri 轮结束时按下“重置”按钮;这些数的顺序可任意。若 d=0,则第二行可留空,或完全不输出第二行。
若存在多种可行解,输出任意一种即可。
输入输出样例
输入#1
3 4 17 1 3 5 7 3 5 7 9 11 17 5 2 8 2 4 6 1 2 7 2 5 4 6 3 3 5 1 7 4 2 5 3 6 17 6 1 2 7 2 5 1 7 4 2 5 3
输出#1
0 2 2 4 -1
说明/提示
In the second test case, if the human pushes the "Reset" button after the second and the fourth rounds, the game goes as follows:
- after the first round the human has 5 points, the computer — 4 points;
- after the second round the human has 7 points, the computer — 10 points;
- the human pushes the "Reset" button and now he has 0 points and the computer — 3 points;
- after the third round the human has 8 points, the computer — 6 points;
- after the fourth round the human has 10 points, the computer — 9 points;
- the human pushes "Reset" button again, after it he has 1 point, the computer — 0 points;
- after the fifth round the human has 5 points, the computer — 5 points;
- after the sixth round the human has 11 points, the computer — 6 points;
- after the seventh round the human has 12 points, the computer — 13 points;
- after the eighth round the human has 14 points, the computer — 17 points;
- the human wins, as the computer has k or more points and the human — strictly less than k points.
在第二个测试用例中,如果人类在第二轮和第四轮后按下“重置”按钮,则游戏过程如下:
- 第一轮结束后,人类得分为 5 分,计算机得分为 4 分;
- 第二轮结束后,人类得分为 7 分,计算机得分为 10 分;
- 人类按下“重置”按钮,此时人类得分为 0 分,计算机得分为 3 分;
- 第三轮结束后,人类得分为 8 分,计算机得分为 6 分;
- 第四轮结束后,人类得分为 10 分,计算机得分为 9 分;
- 人类再次按下“重置”按钮,按下后人类得分为 1 分,计算机得分为 0 分;
- 第五轮结束后,人类得分为 5 分,计算机得分为 5 分;
- 第六轮结束后,人类得分为 11 分,计算机得分为 6 分;
- 第七轮结束后,人类得分为 12 分,计算机得分为 13 分;
- 第八轮结束后,人类得分为 14 分,计算机得分为 17 分;
- 人类获胜,因为此时计算机得分已达 k 分或以上,而人类得分严格小于 k 分。
输入解题思路,AI测评打分。不知道怎么写?