Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.1 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;
    
    public:
        Stack(int s) {
            arr.resize(s);
        };

        bool isEmpty(){
            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 (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;
}