-
Notifications
You must be signed in to change notification settings - Fork 1
/
1136.java
40 lines (31 loc) · 1.16 KB
/
1136.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
import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
while(line != null && line.length() > 0) {
String[] splitLine = line.split(" ");
int N = Integer.parseInt(splitLine[0]);
int B = Integer.parseInt(splitLine[1]);
line = reader.readLine();
if (line == null) {
break;
}
String[] bolasInput = line.split(" ");
int[] bolas = new int[B];
for(int i=0; i<B; i++){
bolas[i] = Integer.parseInt(bolasInput[i]);
}
Set<Integer> possibilities = new HashSet<>();
possibilities.add(0);
for(int i = 0; i < B; ++i) {
for(int j = i + 1; j < B; ++j) {
possibilities.add(Math.abs(bolas[i] - bolas[j]));
}
}
System.out.println(possibilities.size() == N + 1 ? "Y" : "N");
line = reader.readLine();
}
}
}