• + 0 comments
    {
        stack<int> a1;
        stack<int> b1;
        int val = 0;
        int tmp = 0;
        int t = 0;
        for (int i = a.size() - 1; i >= 0; i--)
        {
            a1.push(a[i]);
        }
        for (int i = b.size() - 1; i >= 0; i--)
        {
            b1.push(b[i]);
        }
    
        while (tmp <= maxSum && (!a1.empty() || !b1.empty()))
        {
            val = t;
    
            if (!a1.empty() && (b1.empty() || a1.top() <= b1.top()))
            {
                tmp += a1.top();
                a1.pop();
                t += 1;
            }
            else if (!b1.empty())
            {
                tmp += b1.top();
                b1.pop();
                t += 1;
            }
        }
        return val;
    }
    

    what is the problem