제로

PHOTO EMBED

Sun Feb 25 2024 07:38:25 GMT+0000 (Coordinated Universal Time)

Saved by @hajinjang0714

#include <iostream>
#include <stack>
using namespace std;
int main()
{
    long long i, a, j, cnt=0;
    stack<int> st;
    cin>>a;
    for(i=1;i<=a;i++)
    {
        cin>>j;
        if(j!=0)
        {
            st.push(j);
            cnt+=j;
        }
        else
        {
            cnt-=st.top();
            st.pop();
        }
    }
    cout<<cnt;
}
content_copyCOPY

https://www.acmicpc.net/submit/10773/71653961