# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
541334 | AlperenT | Po (COCI21_po) | C++17 | 11 ms | 3028 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long n, arr[N], nxt[N], upd[N], cur, ans;
stack<int> stck;
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
cin >> n;
for(int i = 1; i <= n; i++) cin >> arr[i];
arr[n + 1] = -1;
stck.push(n + 1);
for(int i = n; i >= 1; i--){
while(arr[stck.top()] >= arr[i]) stck.pop();
nxt[i] = stck.top();
stck.push(i);
}
for(int i = 1; i <= n; i++){
cur += upd[i];
if(cur == arr[i]) continue;
else{
upd[nxt[i]] -= arr[i] - cur;
ans++;
cur += arr[i] - cur;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |