-
Notifications
You must be signed in to change notification settings - Fork 0
/
SacramentOfSum.java
43 lines (35 loc) · 975 Bytes
/
SacramentOfSum.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
41
42
43
import java.util.*;
import java.io.*;
public class SacramentOfSum
{
public static void main(String[] argv) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
List<Integer> first = new ArrayList<>();
List<Integer> second = new ArrayList<>();
int n = in.nextInt();
while (n-- > 0) {
first.add(in.nextInt());
}
n = in.nextInt();
while (n-- > 0) {
second.add(in.nextInt());
}
int i = 0;
int j = 0;
while (i < first.size() && j < second.size()) {
int sum = first.get(i) + second.get(j);
if (sum > 10000) {
j++;
}
else if (sum < 10000) {
i++;
}
else {
System.out.println("YES");
return;
}
}
System.out.println("NO");
}
}