-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnopair.java
More file actions
30 lines (29 loc) · 714 Bytes
/
Copy pathnopair.java
File metadata and controls
30 lines (29 loc) · 714 Bytes
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
import java.util.*;
class nopair{
public static int getValue(int[] ar,int k){
int count = 0;
HashSet<Integer> hash = new HashSet<>();
for(int i=0;i<ar.length;i++)
hash.add(ar[i]+k);
Iterator i = hash.iterator();
int start = 0;
while(i.hasNext()){
int te =(int) i.next();
while(start<ar.length)
if(te==ar[start++]){
count++;
break;
}
}
return count;
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int k = s.nextInt();
int ar[] = new int[n];
for(int i=0;i<n;i++) ar[i] = s.nextInt();
Arrays.sort(ar);
System.out.println(getValue(ar,k));
}
}