Submission #531761

#TimeUsernameProblemLanguageResultExecution timeMemory
531761devariaotaMoney (IZhO17_money)C++17
0 / 100
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; int main(){ cin.tie(0) -> ios_base::sync_with_stdio(0); int n; cin >> n; vector<int> a(n); for(int i=0;i<n;i++) cin >> a[i]; set<int> s; int ans = 0, i = 0; while(i < n) { s.insert(a[i]); if(a[i + 1] < a[i]) break; i++; } for(;i<n;i++) { auto x = s.upper_bound(a[i-1]); ans++; int y; if(x == s.end()) { y = a[i]; while(i < n) { s.insert(a[i]); if(a[i + 1] < a[i]) break; i++; } } else if(a[i] <= *x) { y = *x; while(i < n && a[i] <= y) { s.insert(a[i]); if(a[i + 1] < a[i]) break; i++; } } else // a[i] > the el after prev element { s.insert(a[i]); } } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...