# Untitled

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

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

// Stack class to represent a stack
class Stack{
private:
vector<int> arr_stack;

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

bool isEmpty(){
return (arr_stack.size() == 0);
}

void push(int value){
arr_stack.push_back(value);
}

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

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

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

void stackify(){
reverse(arr_stack.begin(), arr_stack.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 temp;
int sum1 = 0, sum2 = 0, sum3 = 0;
while (n1--){
cin >> temp;
s1.push(temp);
sum1 += temp;
}
s1.stackify();
while (n2--){
cin >> temp;
s2.push(temp);
sum2 += temp;
}
s2.stackify();
while (n3--){
cin >> temp;
s3.push(temp);
sum3 += temp;
}
s3.stackify();

while (n1 != 0 && n2 != 0 && n3 != 0){
if (sum1 == sum2 && sum1 == sum3){
cout << sum1;
return 0;
}
else if (sum1 >= sum2 && sum1 >= sum3){
sum1 -= s1.top();
s1.pop();
n1--;
}
else if (sum2 >= sum1 && sum2 >= sum3){
sum2 -= s2.top();
s2.pop();
n2--;
}
else if (sum3 >= sum2 && sum3 >= sum1){
sum3 -= s3.top();
s3.pop();
n3--;
}

}

cout << "\n";

// cout << "top 1 is " << s1.top();
// cout << "top 2 is " << s2.top();
// cout << "top 3 is " << s3.top();
return 0;
}```