#P12953. [GCJ Farewell Round #2] Spacious Sets

    ID: 12755 Type: RemoteJudge 20000ms 2048MiB Tried: 0 Accepted: 0 Difficulty: 3 Uploaded By: Tags>递推二分2023Google Code Jam

[GCJ Farewell Round #2] Spacious Sets

题目描述

Ada and John are best friends. Since they are getting bored, Ada asks John to solve a puzzle for her.

A set SS is considered spacious if the absolute difference between each pair of distinct elements of SS is at least K\mathbf{K}, that is, xyK|x - y| \geq \mathbf{K} for all x,ySx, y \in S, with xyx \neq y.

Ada has a list of distinct integers A\mathbf{A} of size N\mathbf{N}, and an integer K\mathbf{K}. For each Ai\mathbf{A}_i, she asks John to find the maximum size of a set SiS_i made of elements from A\mathbf{A}, such that SiS_i contains Ai\mathbf{A}_i and is spacious.

Note: The sets SiS_i do not need to be made of consecutive elements from the list.

输入格式

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow. The first line of each test case contains two integers N\mathbf{N} and K\mathbf{K}. The next line contains N\mathbf{N} integers $\mathbf{A}_1 \mathbf{A}_2 \ldots \mathbf{A}_{\mathbf{N}}$.

输出格式

For each test case, output one line containing Case # xx: y1 y2 yNy_1 \ y_2 \ldots \ y_{\mathbf{N}}, where xx is the test case number (starting from 1) and yiy_i is the maximum size of a spacious set of elements from A\mathbf{A} that contains Ai\mathbf{A}_i.

2
3 2
1 2 3
6 4
2 7 11 19 5 3
Case #1: 2 1 2
Case #2: 4 4 4 4 3 4

提示

Sample Explanation

In Sample Case #1, a spacious set cannot contain 11 and 22, nor it can contain 22 and 33. That implies that S2={2}S_2 = \{2\} and using S1=S3={1,3}S_1 = S_3 = \{1, 3\} makes them of maximum size.

In Sample Case #2, possible sets of maximum size are:

  • S1=S2=S3=S4={2,7,11,19}S_1 = S_2 = S_3 = S_4 = \{2, 7, 11, 19\},
  • S5={11,19,5}S_5 = \{11, 19, 5\}, and
  • S6={7,11,19,3}S_6 = \{7, 11, 19, 3\}.

Limits

  • 1T1001 \leq \mathbf{T} \leq 100.
  • 109Ai109-10^9 \leq \mathbf{A}_i \leq 10^9, for all ii.
  • AiAj\mathbf{A}_i \neq \mathbf{A}_j, for all iji \neq j.

Test Set 1 (4 Pts, Visible Verdict)

  • 1N101 \leq \mathbf{N} \leq 10.
  • 1K1001 \leq \mathbf{K} \leq 100.

Test Set 2 (10 Pts, Visible Verdict)

  • 1K1091 \leq \mathbf{K} \leq 10^9.

For at most 15 cases:

  • 1N1051 \leq \mathbf{N} \leq 10^5.

For the remaining cases:

  • 1N1031 \leq \mathbf{N} \leq 10^3.