forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
53 lines (47 loc) · 1.33 KB
/
Solution.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
44
45
46
47
48
49
50
51
52
53
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n1 = in.nextInt();
int n2 = in.nextInt();
int n3 = in.nextInt();
int h1[] = new int[n1];
for(int h1_i=0; h1_i < n1; h1_i++){
h1[h1_i] = in.nextInt();
}
int h2[] = new int[n2];
for(int h2_i=0; h2_i < n2; h2_i++){
h2[h2_i] = in.nextInt();
}
int h3[] = new int[n3];
for(int h3_i=0; h3_i < n3; h3_i++){
h3[h3_i] = in.nextInt();
}
HashMap<Integer, Integer> cache = new HashMap<Integer, Integer>();
int acc = 0;
for (int i = n1 - 1; i >= 0; i--) {
acc += h1[i];
cache.put(acc, 1);
}
acc = 0;
for (int i = n2 - 1; i >= 0; i--) {
acc += h2[i];
if (cache.containsKey(acc)) {
cache.put(acc, cache.get(acc) + 1);
}
}
acc = 0;
int max = 0;
for (int i = n3 - 1; i >= 0; i--) {
acc += h3[i];
if (cache.containsKey(acc) && cache.get(acc) == 2) {
max = acc;
}
}
System.out.println(max);
}
}