欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1481B.New Colony
New Colony
After reaching your destination, you want to build a new colony on the new planet. Since this planet has many mountains and the colony must be built on a flat surface you decided to flatten the mountains using boulders (you are still dreaming so this makes sense to you).

You are given an array , where is the height of the -th mountain, and — the number of boulders you have.
You will start throwing boulders from the top of the first mountain one by one and they will roll as follows (let's assume that the height of the current mountain is ):
- if , the boulder will roll to the next mountain;
- if , the boulder will stop rolling and increase the mountain height by ();
- if the boulder reaches the last mountain it will fall to the waste collection system and disappear.
You want to find the position of the -th boulder or determine that it will fall into the waste collection system.
Input
The first line contains a single integer () — the number of test cases.
Each test case consists of two lines. The first line in each test case contains two integers and (; ) — the number of mountains and the number of boulders.
The second line contains integers () — the height of the mountains.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print if the -th boulder will fall into the collection system. Otherwise, print the position of the -th boulder.
Note
Let's simulate the first case:
- The first boulder starts at ; since it rolls to and stops there because .
- The new heights are .
- The second boulder starts at ; since the boulder rolls to ; since the boulder rolls to and stops there because .
- The new heights are .
- The third boulder starts at ; since it rolls to and stops there because .
- The new heights are .
The positions where each boulder stopped are the following: .
In the second case, all boulders will stop right at the first mountain rising its height from to .
The third case is similar to the first one but now you'll throw boulders. The first three will roll in the same way as in the first test case. After that, mountain heights will be equal to , that's why the other two boulders will fall into the collection system.
In the fourth case, the first and only boulders will fall straight into the collection system.
Samples
4
4 3
4 1 2 3
2 7
1 8
4 5
4 1 2 3
3 1
5 3 1
2
1
-1
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |