CF1409E.Two Platforms

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn points on a plane. The ii-th point has coordinates (xi,yi)(x_i, y_i). You have two horizontal platforms, both of length kk. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same yy-coordinate) and have integer borders. If the left border of the platform is (x,y)(x, y) then the right border is (x+k,y)(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 yy-coordinate.

When you place both platforms on a plane, all points start falling down decreasing their yy-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 tt independent test cases.

For better understanding, please read the Note section below to see a picture for the first test case.

平面上有 nn 个点,其中第 ii 个点的坐标为 (xi,yi)(x_i, y_i)。你有两个长度均为 kk 的水平平台。每个平台可放置在平面上任意位置,但必须保持水平(即所有点具有相同的 yy 坐标),且其左右边界横坐标均为整数。若某平台左边界坐标为 (x,y)(x, y),则其右边界坐标为 (x+k,y)(x + k, y),且左右边界之间(含边界)的所有点均属于该平台。

注意:两个平台可以重叠(即共享公共点),且它们不必放置在同一 yy 坐标上。

当你将两个平台放置在平面上后,所有点开始向下自由下落(即其 yy 坐标不断减小)。若某个点在下落过程中于某一时刻与任一平台发生碰撞,则该点立即停止下落并被成功拯救;而从未与任何平台碰撞的点则丢失。

你的任务是:通过最优地放置这两个平台,求出最多能拯救的点的数量。

你需要处理 tt 组相互独立的测试用例。

为便于理解,请参阅下方“说明”部分中第一个测试用例对应的示意图。

输入格式

The first line of the input contains one integer tt (1≤t≤2⋅1041 \le t \le 2 \cdot 10^4) — the number of test cases. Then tt test cases follow.

The first line of the test case contains two integers nn and kk (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5; 1≤k≤1091 \le k \le 10^9) — the number of points and the length of each platform, respectively. The second line of the test case contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (1≤xi≤1091 \le x_i \le 10^9), where xix_i is xx-coordinate of the ii-th point. The third line of the input contains nn integers y1,y2,…,yny_1, y_2, \dots, y_n (1≤yi≤1091 \le y_i \le 10^9), where yiy_i is yy-coordinate of the ii-th point. All points are distinct (there is no pair 1≤i<j≤n1 \le i \lt j \le n such that xi=xjx_i = x_j and yi=yjy_i = y_j).

It is guaranteed that the sum of nn does not exceed 2⋅1052 \cdot 10^5 (∑n≤2⋅105\sum n \le 2 \cdot 10^5).

输入的第一行包含一个整数 tt(1≤t≤2⋅1041 \le t \le 2 \cdot 10^4),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含两个整数 nn 和 kk(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5;1≤k≤1091 \le k \le 10^9),分别表示点的数量和每个平台的长度。每个测试用例的第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(1≤xi≤1091 \le x_i \le 10^9),其中 xix_i 表示第 ii 个点的 xx-坐标。输入的第三行包含 nn 个整数 y1,y2,…,yny_1, y_2, \dots, y_n(1≤yi≤1091 \le y_i \le 10^9),其中 yiy_i 表示第 ii 个点的 yy-坐标。所有点互不相同(即不存在满足 1≤i<j≤n1 \le i \lt j \le n 且 xi=xjx_i = x_j、yi=yjy_i = y_j 的点对)。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5(即 ∑n≤2⋅105\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:

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)(1, -1) and (2,−1)(2, -1) and the second one between points (4,3)(4, 3) and (5,3)(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)(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)(5, 3) doesn't fall at all because it is already on the platform.

示例中第一个测试用例对应的图片:

蓝色圆点表示各点,红色线段表示平台。一种可行的方案是:将第一个平台放置在点 (1,−1)(1, -1) 与 (2,−1)(2, -1) 之间,第二个平台放置在点 (4,3)(4, 3) 与 (5,3)(5, 3) 之间。箭头表示各点下落的方向。如图所示,唯一无法被拯救的点是 (3,7)(3, 7),它将无限下落并最终丢失。可以证明,本例中无法得到更优的答案。另外请注意,点 (5,3)(5, 3) 完全不会下落,因为它已恰好位于某个平台上。

输入解题思路,AI测评打分。不知道怎么写?

首页