# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1153772 | YSH2020 | Po (COCI21_po) | C++20 | 22 ms | 836 KiB |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n; cin >> n;
int a[n+1]; for (int i = 0; i < n; i++) cin >> a[i];
stack<int> x;
int ans = 0;
for (int i = 0; i < n; i++) {
int taken = 0;
while (x.size() > 0 and x.top() > a[i]) {
if (taken == 0) {
ans += x.top()-a[i];
taken = 1;
}
x.pop();
}
x.push(a[i]);
}
ans += x.top();
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |