Submission #541333

#TimeUsernameProblemLanguageResultExecution timeMemory
541333AlperenTPo (COCI21_po)C++17
20 / 70
13 ms3412 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int 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]; 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 timeMemoryGrader output
Fetching results...