-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChopSticks.java
40 lines (35 loc) · 982 Bytes
/
ChopSticks.java
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
package problems.codechef;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
/**
* Created by arpit on 10/1/17.
*/
public class ChopSticks {
static final int MAX=100000;
static int a[]=new int[MAX];
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int n,d;
String[]s;
s=br.readLine().split("\\s");
n=Integer.parseInt(s[0]);
d=Integer.parseInt(s[1]);
for (int i = 0; i < n; i++) {
a[i]=Integer.parseInt(br.readLine());
}
System.out.println(solve(a,n,d));
}
private static int solve(int[] a, int n, int d) {
Arrays.sort(a,0,n);
int ans=0;
for (int i = 1; i <n ; i++) {
if (a[i]-a[i-1]<=d){
ans++;
i++;
}
}
return ans;
}
}