# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
963961 | Aiperiii | Money (IZhO17_money) | C++14 | 1 ms | 432 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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n;
cin>>n;
vector <int> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
vector <vector <int> > vec;
vector <int> v;
for(int i=1;i<=n;i++){
if(a[i]>=a[i-1]){
v.pb(a[i]);
}
else{
vec.pb(v);
v.clear();
v.pb(a[i]);
}
}
vec.pb(v);
multiset <int> ms;
for(auto x : vec[0])ms.insert(x);
int ans=1;
for(int i=1;i<vec.size();i++){
int pos=0;
while(pos<vec[i].size()){
int x=vec[i][pos];
auto it=ms.upper_bound(x);
int up=*it;
if(it==ms.end()){
ans++;
break;
}
else{
auto it=upper_bound(all(vec[i]),up);
ans++;
int new_pos=it-vec[i].begin();
for(int j=pos;j<new_pos;j++)ms.insert(vec[i][pos]);
pos=new_pos;
}
}
}
cout<<ans<<"\n";
}
/*
6
3 6 4 5 1 2
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |