아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Spacious Sets

시간 제한20초메모리 제한1024 MB

요약
서로 다른 정수들과 간격 K가 주어질 때, 각 원소를 포함하면서 모든 쌍의 차이가 K 이상인 최대 부분집합의 크기를 구한다.
난이도

보통10점 중 7점

유형
정렬, 그리디, 누적 합
정답자
아직 제출이 없습니다

문제

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, ∣x−y∣≥K|x - y| \ge \mathbf{K} for all x,y∈Sx, y \in S, with x≠yx \ne y.

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

Note: The sets S_iS\_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 A_1A_2…A_N\mathbf{A\_1} \mathbf{A\_2} \dots \mathbf{A\_N}.

출력

For each test case, output one line containing Case #x: y1 y2 ... yN$, where xx is the test case number (starting from 1) and y_iy\_i is the maximum size of a spacious set of elements from A\mathbf{A} that contains A_i\mathbf{A\_i}.

제한

  • 1≤T≤1001 \le \mathbf{T} \le 100.
  • −109≤A_i≤109-10^9 \le \mathbf{A\_i} \le 10^9, for all ii.
  • A_i≠A_j\mathbf{A\_i} \ne \mathbf{A\_j}, for all i≠ji \ne j.

힌트

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

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

  • S_1=S_2=S_3=S_4=2,7,11,19S\_1 = S\_2 = S\_3 = S\_4 = \\{2,7,11,19\\},
  • S_5=11,19,5S\_5 = \\{11,19,5\\}, and
  • S_6=7,11,19,3S\_6 = \\{7,11,19,3\\}.

예제1

  1. 예제 1

    입력
    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