欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1450B.Balls of Steel
Balls of Steel
You have distinct points on the plane and a non-negative integer parameter . Each point is a microscopic steel ball and is the attract power of a ball when it's charged. The attract power is the same for all balls.
In one operation, you can select a ball to charge it. Once charged, all balls with Manhattan distance at most from ball move to the position of ball . Many balls may have the same coordinate after an operation.
More formally, for all balls such that , we assign and .
An example of an operation. After charging the ball in the center, two other balls move to its position. On the right side, the red dot in the center is the common position of those balls.
Your task is to find the minimum number of operations to move all balls to the same position, or report that this is impossible.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains two integers , (, ) — the number of balls and the attract power of all balls, respectively.
The following lines describe the balls' coordinates. The -th of these lines contains two integers , () — the coordinates of the -th ball.
It is guaranteed that all points are distinct.
Output
For each test case print a single integer — the minimum number of operations to move all balls to the same position, or if it is impossible.
Note
In the first test case, there are three balls at , , and and the attract power is . It is possible to move two balls together with one operation, but not all three balls together with any number of operations.
In the second test case, there are three balls at , , and and the attract power is . If we charge any ball, the other two will move to the same position, so we only require one operation.
In the third test case, there are four balls at , , , and , and the attract power is . We can show that it is impossible to move all balls to the same position with a sequence of operations.
Samples
3
3 2
0 0
3 3
1 1
3 3
6 7
8 8
6 9
4 1
0 0
0 1
0 2
0 3
-1
1
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |