# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
359047 | 2021-01-26T09:35:27 Z | Ahmad_Hasan | Money (IZhO17_money) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; int ans=0; unordered_multiset<int>ms; int f=0; int l=0; for(int i=0;i<n;i++){ unordered_multiset<int>::iterator it1=ms.lower_bound(v[i]); unordered_multiset<int>::iterator it2=ms.upper_bound(v[i]); if((i+1<n)&&(v[i+1]<v[i]||(it2!=ms.end()&&*it2<v[i+1])||(it1!=ms.end()&&*it1>v[l]&&*it1<v[i+1]))){ ans++; for(int j=l;j<=i;j++) ms.insert(v[j]); l=i+1; } if(i==n-1) ans++; } cout<<ans<<'\n'; return 0; } /** 7 2 4 6 1 3 5 7 6 3 6 4 5 1 2 */