Two Platforms

题意翻译

# 题目描述 给出平面上 $n$ 个点,第 $i$ 个点为 $(x_i, y_i)$。 定义一个`平台`为与 $x$ 轴平行的一条长度为 $k$ 的线段。 你有两个 `平台`,并且可以选择每个 `平台` 的放置位置。 确定 `平台` 位置之后, `平面` 上的点会下落(即:点的 $y$ 坐标开始减小),当这个点落在遇到某一个 `平台` 时,就停止下落。 如果这个点始终没能遇到一个 `平台`,那么这个点就成为了 **时代的眼泪** ,即 **丢失** 了。 求一种放置 `平台` 的方法,最大化平台能“接住”的点。输出最大的接住点的个数。 # 输入描述 第一行一个整数 $t$, ($ 1 \le t \le 2 \cdot 10^4 $) 表示测试数据的组数。接下来是 t 组数据。 对于每一组数据: 第一行包含两个整数$ n $ 和 $ k $ ( $ 1 \le n \le 2 \cdot 10^5 $ ; $ 1 \le k \le 10^9 $ ) 第二行包含 $n$ 个整数,第 $i$ 个整数为第 $i$ 个点的横坐标 $x_i$ 第三行包含 $n$ 个整数,第 $i$ 个整数为第 $i$ 个点的纵坐标 $y_i$ # 输出描述 对于每组测试数据,输出一个整数,表示能“接住”的最多的点数。 # 样例解释 对样例一的解释如图: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1409E/939a53d6a5db677af525f764b29caa6d8ff8f49a.png)

题目描述

There are $ n $ points on a plane. The $ i $ -th point has coordinates $ (x_i, y_i) $ . 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 \le t \le 2 \cdot 10^4 $ ) — the number of test cases. Then $ t $ test cases follow. The first line of the test case contains two integers $ n $ and $ k $ ( $ 1 \le n \le 2 \cdot 10^5 $ ; $ 1 \le k \le 10^9 $ ) — the number of points and the length of each platform, respectively. The second line of the test case contains $ n $ integers $ x_1, x_2, \dots, x_n $ ( $ 1 \le x_i \le 10^9 $ ), where $ x_i $ is $ x $ -coordinate of the $ i $ -th point. The third line of the input contains $ n $ integers $ y_1, y_2, \dots, y_n $ ( $ 1 \le y_i \le 10^9 $ ), where $ y_i $ is $ y $ -coordinate of the $ i $ -th point. All points are distinct (there is no pair $ 1 \le i < j \le n $ such that $ x_i = x_j $ and $ y_i = y_j $ ). It is guaranteed that the sum of $ n $ does not exceed $ 2 \cdot 10^5 $ ( $ \sum n \le 2 \cdot 10^5 $ ).

输出格式


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: ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1409E/939a53d6a5db677af525f764b29caa6d8ff8f49a.png) 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.