Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.1 kB
2
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> array;
    
    public:
        Stack() {};

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

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

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

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

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

        void reverse_input(){
            reverse(array.begin(), array.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;
    Stack s2;
    Stack s3;

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

    s1.reverse_input();
    s2.reverse_input();
    s3.reverse_input();
    

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

    }

    
    cout << "0\n";

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