Submission
Status:
PPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: sakuragichan
Problemset: ประมูลการกุศล
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-09 21:18:13
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,sum = 0;
cin >> n;
stack<int> arr;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (arr.empty()) {
arr.push(x);
sum += x;
} else {
if (x > arr.top()){
sum += x;
arr.push(x);
}
}
}
cout << sum << endl;
}