# Untitled

unknown
plain_text
2 years ago
2.0 kB
1
Indexable
Never
```//Please do not modify the header files.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

class Stack{
private:
vector<int> arr;

public:
Stack(int s) {
arr.resize(s);
};

bool empty(){
return (arr.size() == 0);
}

void push(int x){
arr.push_back(x);
}

int top(){
return arr.back();
}

void pop(){
arr.pop_back();
}

int size() {
return arr.size();
}

void stackify(){
reverse(arr.begin(), arr.end());
}

};

int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */

int n1, n2, n3;
cin >> n1 >> n2 >> n3;

Stack s1(n1);
Stack s2(n2);
Stack s3(n3);

int tmp;
int sum1 = 0, sum2 = 0, sum3 = 0;
while (n1--){
cin >> tmp;
s1.push(tmp);
sum1 += tmp;
}
s1.stackify();
while (n2--){
cin >> tmp;
s2.push(tmp);
sum2 += tmp;
}
s2.stackify();
while (n3--){
cin >> tmp;
s3.push(tmp);
sum3 += tmp;
}
s3.stackify();

while (!s1.empty() || s2.empty() || s3.empty()){
if ((sum1 > sum2 && sum1 >= sum3) || (sum1 >= sum2 && sum1 > sum3)){
sum1 -= s1.top();
s1.pop();
}
else if ((sum2 > sum3 && sum2 >= sum1) || (sum2 >= sum3 && sum2 > sum1)){
sum2 -= s2.top();
s2.pop();
}
else if ((sum3 > sum1 && sum3 >= sum2) || (sum3 >= sum1 && sum3 > sum2)){
sum3 -= s3.top();
s3.pop();
}

if (sum1 == sum2 && sum1 == sum3){
cout << sum1;
return 0;
}
}

cout << 0;
return 0;
}```