Preview:
#include <iostream>
#include <list>

using namespace std;

int main()
{
    list<int> a,b,c;
    long A = 0, B = 0, C = 0, x = 0, num[3];
    int height = 0;

    cin >> num[0] >> num[1] >> num[2];

    while(num[0]--){
        cin >> height;
        a.push_back(height);
        A += height;
    }

  
    while(num[1]--){
        cin >> height;
        b.push_back(height);
        B += height;
    }

 
    while(num[2]--){
        cin >> height;
        c.push_back(height);
        C += height;
    }

    list<int> :: iterator itr1, itr2, itr3;

    itr1 = a.begin();
    itr2 = b.begin();
    itr3 = c.begin();

    while(A != B || B != C){
    
        x = max(A,B);
        x = max(x,C);

 
        if(A == x){
            A -=(*itr1);
            ++itr1;
        }
        if(B == x){
            B -= (*itr2);
            ++itr2;
        }
        if(C == x){
            C -= (*itr3);
            ++itr3;
        }
    }

 
    cout << A << endl;

    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter