CF1409E.Two Platforms
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n points on a plane. The i -th point has coordinates (xi,yi) . You have two horizontal platforms, both of length k . Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same y -coordinate) and have integer borders. If the left border of the platform is (x,y) then the right border is (x+k,y) and all points between borders (including borders) belong to the platform.
Note that platforms can share common points (overlap) and it is not necessary to place both platforms on the same y -coordinate.
When you place both platforms on a plane, all points start falling down decreasing their y -coordinate. If a point collides with some platform at some moment, the point stops and is saved. Points which never collide with any platform are lost.
Your task is to find the maximum number of points you can save if you place both platforms optimally.
You have to answer t independent test cases.
For better understanding, please read the Note section below to see a picture for the first test case.
输入格式
The first line of the input contains one integer t ( 1≤t≤2⋅104 ) — the number of test cases. Then t test cases follow.
The first line of the test case contains two integers n and k ( 1≤n≤2⋅105 ; 1≤k≤109 ) — the number of points and the length of each platform, respectively. The second line of the test case contains n integers x1,x2,…,xn ( 1≤xi≤109 ), where xi is x -coordinate of the i -th point. The third line of the input contains n integers y1,y2,…,yn ( 1≤yi≤109 ), where yi is y -coordinate of the i -th point. All points are distinct (there is no pair 1≤i<j≤n such that xi=xj and yi=yj ).
It is guaranteed that the sum of n does not exceed 2⋅105 ( ∑n≤2⋅105 ).
输出格式
For each test case, print the answer: the maximum number of points you can save if you place both platforms optimally.
输入输出样例
输入#1
4 7 1 1 5 2 3 1 5 4 1 3 6 7 2 5 4 1 1 1000000000 1000000000 5 10 10 7 5 15 8 20 199 192 219 1904 10 10 15 19 8 17 20 10 9 2 10 19 12 13 6 17 1 14 7 9 19 3
输出#1
6 1 5 10
说明/提示
The picture corresponding to the first test case of the example:
Blue dots represent the points, red segments represent the platforms. One of the possible ways is to place the first platform between points (1,−1) and (2,−1) and the second one between points (4,3) and (5,3) . Vectors represent how the points will fall down. As you can see, the only point we can't save is the point (3,7) so it falls down infinitely and will be lost. It can be proven that we can't achieve better answer here. Also note that the point (5,3) doesn't fall at all because it is already on the platform.