-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_12005.java
More file actions
45 lines (38 loc) · 1.15 KB
/
Copy pathBOJ_12005.java
File metadata and controls
45 lines (38 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// BOJ - 12005
// Problem Sheet - https://www.acmicpc.net/problem/12005
import java.util.*;
import java.io.*;
public class Main {
private static int n, k;
private static int[] diamond;
public static void main(String[] args) throws IOException {
input();
System.out.println(solve());
}
private static void input() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] row = br.readLine().split(" ");
n = Integer.parseInt(row[0]);
k = Integer.parseInt(row[1]);
diamond = new int[n];
for (int i=0 ; i<n ; i++) {
diamond[i] = Integer.parseInt(br.readLine());
}
Arrays.sort(diamond);
br.close();
}
private static int solve() {
int left = 0, right = 0;
int maxCnt = 0;
while (right < n) {
if (diamond[right] - diamond[left] <= k) {
maxCnt = Math.max(maxCnt, right - left);
right++;
} else {
left++;
if (left > right) right = left;
}
}
return maxCnt + 1;
}
}