-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEqual Stacks.cpp
More file actions
57 lines (46 loc) · 1.15 KB
/
Equal Stacks.cpp
File metadata and controls
57 lines (46 loc) · 1.15 KB
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
54
55
56
57
//Author: Bishal Sarang
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
vector < long long > A(a), B(b), C(c);
vector < long long > sum_A(a), sum_B(b), sum_C(c);
unordered_map < long long, long long > check;
for (int i = 0; i < a; i++) {
cin >> A[i];
}
sum_A[0] = A[a - 1];
check[sum_A[0]]++;
for (int i = a - 2, j = 1; i >= 0; i--, j++) {
sum_A[j] = sum_A[j - 1] + A[i];
check[sum_A[j]]++;
}
for (int i = 0; i < b; i++) {
cin >> B[i];
}
sum_B[0] = B[b - 1];
check[sum_B[0]]++;
for (int i = b - 2, j = 1; i >= 0; i--, j++) {
sum_B[j] = sum_B[j - 1] + B[i];
check[sum_B[j]]++;
}
for (int i = 0; i < c; i++) {
cin >> C[i];
}
sum_C[0] = C[c - 1];
check[sum_C[0]]++;
for (int i = c - 2, j = 1; i >= 0; i--, j++) {
sum_C[j] = sum_C[j - 1] + C[i];
check[sum_C[j]]++;
}
vector < long long > heights;
heights.push_back(0);
for (auto x: check) {
if (x.second == 3) {
heights.push_back(x.first);
}
}
cout << * max_element(heights.begin(), heights.end());
return 0;
}