欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1956A.Nene's Game
Nene's Game
Nene invented a new game based on an increasing sequence of integers .
In this game, initially players are lined up in a row. In each of the rounds of this game, the following happens:
- Nene finds the -th, -th, , -th players in a row. They are kicked out of the game simultaneously. If the -th player in a row should be kicked out, but there are fewer than players in a row, they are skipped.
Once no one is kicked out of the game in some round, all the players that are still in the game are declared as winners.
For example, consider the game with and players. Let the players be named player A, player B, , player E in the order they are lined up initially. Then,
- Before the first round, players are lined up as
ABCDE. Nene finds the -rd and the -th players in a row. These are playersCandE. They are kicked out in the first round. - Now players are lined up as
ABD. Nene finds the -rd and the -th players in a row. The -rd player is playerDand there is no -th player in a row. Thus, only playerDis kicked out in the second round. - In the third round, no one is kicked out of the game, so the game ends after this round.
- Players
AandBare declared as the winners.
Nene has not yet decided how many people would join the game initially. Nene gave you integers and you should answer the following question for each independently:
- How many people would be declared as winners if there are players in the game initially?
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of test cases follows.
The first line case contains two integers and () — the length of the sequence and the number of values you should solve this problem for.
The second line contains integers () — the sequence .
The third line contains integers ().
Output
For each test case, output integers: the -th () of them should be the number of players declared as winners if initially players join the game.
Note
The first test case was explained in the statement.
In the second test case, when , the only player stays in the game in the first round. After that, the game ends and the only player is declared as a winner.
Samples
6
2 1
3 5
5
5 3
2 4 6 7 9
1 3 5
5 4
3 4 5 6 7
1 2 3 4
2 3
69 96
1 10 100
1 1
100
50
3 3
10 20 30
1 10 100
2
1 1 1
1 2 2 2
1 10 68
50
1 9 9
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |