欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1704B.Luke is a Foodie
Luke is a Foodie
Luke likes to eat. There are piles of food aligned in a straight line in front of him. The -th pile contains units of food.
Luke will walk from the -st pile towards the -th pile, and he wants to eat every pile of food without walking back. When Luke reaches the -th pile, he can eat that pile if and only if , where is a fixed integer, and is Luke's food affinity.
Before Luke starts to walk, he can set to any integer. Also, for each (), Luke can change his food affinity to any integer before he eats the -th pile.
Find the minimum number of changes needed to eat every pile of food.
Note that the initial choice for is not considered as a change.
Input
The input consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
For each test case, the first line contains two integers, (, ) — the number of piles, and the maximum difference between the size of a pile and Luke's food affinity, such that Luke can eat the pile.
The second line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output an integer on a separate line, which is the minimum number of changes needed.
Note
In the first test case, Luke can set to before he starts to walk. And he can walk straight to eat every piles of food without changing .
In the second test case, Luke can set to before he starts to walk. And he could change to before he eats the second pile. After that, he can walk straight to eat remaining food without changing .
In the fourth test case, Luke can set to before he starts to walk. And he could change to before he eats the sixth pile. After that, he can walk straight to eat remaining food without changing .
In the fifth test case, Luke can set to before he starts to walk. And he could change to before he eats the fourth pile. Then he could change to before he eats the seventh pile. After that, he can walk straight to eat remaining food without changing .
Samples
7
5 3
3 8 5 6 7
5 3
3 10 9 8 7
12 8
25 3 3 17 8 6 1 16 15 25 17 23
10 2
1 2 3 4 5 6 7 8 9 10
8 2
2 4 6 8 6 4 12 14
8 2
2 7 8 9 6 13 21 28
15 5
11 4 13 23 7 10 5 21 20 11 17 5 29 16 11
0
1
2
1
2
4
6
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |