• + 0 comments

    int equalStacks(vector h1, vector h2, vector h3) { int n1= accumulate (h1.begin(),h1.end(),0); int n2= accumulate (h2.begin(),h2.end(),0); int n3= accumulate (h3.begin(),h3.end(),0);

    while(true)
    {
        if (n1==n2 && n2==n3)
        {
            break;
        }
    
    
        if (n1>=n2 && n1>=n3)
        {
            n1=n1-h1.front();
            h1.erase(h1.begin());
        }
    
        else if (n2>=n1 && n2>=n3)
        {
            n2=n2-h2.front();
            h2.erase(h2.begin());
        }
    
        else if (n3>=n1 && n3>=n1)
        {
            n3=n3-h3.front();
            h3.erase(h3.begin());
        }
    
    }
    
    return n1;
    

    }