#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define fa(e,l) for(auto e:l)
#define all(arr) arr.begin(),arr.end()
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define coutpii(x) fa(e,x){cout<<e.first<<","<<e.second<<" ";}cout<<"\n"
#define coutll(x) fa(e,x){cout<<r<<" ";}cout<<"\n"
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
ll T,n,k,m,a,b,c=0,d,x,y,z,q,l,r,w;
// cin>>T;
vi arr;
cin>>n;
f(i,0,n){
cin>>x;
arr.pb(x);
}
ll big=arr[0];
ll prev=arr[0];
ll prevbig=arr[0];
vector<pii> sweep;
vi tmp;
f(i,1,n){
if(arr[i]>prev && prev<big){
tmp.pb(big);
tmp.pb(prev);
// sweep.pb({prev,min(big,prevbig)});
big=arr[i];
}//shit here
else if(arr[i]>big){big=arr[i];}
prev=arr[i];
}
tmp.pb(big);
if(tmp.size()<3){cout<<"1";return 0;}
for(ll i=1;i<tmp.size()-1;i+=2){
sweep.pb({tmp[i],min(tmp[i-1],tmp[i+1])});
}
vector<pii> fin;
fa(e,sweep){fin.pb({e.first,0});fin.pb({e.second,1});}
// coutpii(sweep);
// coutpii(fin);
sort(all(fin));
ll ans=1,temp=1;
fa(e,fin){
// cout<<e.first<<" "<<e.second<<"\n";
if(e.second==0){temp++;}
if(e.second==1){temp--;}
ans=max(ans,temp);
}
cout<<ans;
}
/*
Okay
So you need to store
min,min of 2 bigs
*/
| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |