#pragma region 라이브러리
#include <iostream>
#include <cmath>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
#pragma endregion
#pragma region 최적화용
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0);
#define x first
#define x second
using IntPair = pair<int, int>;
using DoubleVec = vector<vector<int>>;
using Vec = vector<int>;
// 상하좌우
IntPair dir[]
{
{ 1, 0 },
{-1, 0 },
{ 0, -1 },
{ 0, 1 }
};
#pragma endregion
int main()
{
int t;
cin >> t;
stack<int> s;
while (t--)
{
int n;
cin >> n;
if (n > 0)
s.push(n);
else
s.pop();
}
int sum = 0;
while (!s.empty())
{
sum += s.top();
s.pop();
}
cout << sum;
return 0;
}
'코딩테스트 > 백준' 카테고리의 다른 글
[브2] 2798 - 블랙잭 (1) | 2024.11.05 |
---|---|
[실4] 9012 - 괄호 (0) | 2024.11.04 |
[브1] 10798 - 세로읽기 (0) | 2024.11.04 |
[브1] 14467 - 소가 길을 건너간 이유 1 (0) | 2024.11.04 |
[실4] 10866 - 덱 (함수포인터 이용) (0) | 2024.08.27 |