이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,x;
cin>>n>>x;
ll t[n+5];
for(ll i=1;i<=n;i++){
cin>>t[i];
}
ll pre[n+5];
vector<ll>v;
for(ll i=1;i<=n;i++){
if(v.empty()||v.back()<t[i]){
v.pb(t[i]);
pre[i]=v.size();
}
else{
ll x=lower_bound(all(v),t[i])-v.begin();
v[x]=t[i];
pre[i]=x+1;
}
}
v.clear();
ll suf[n+5];
suf[n+1]=0;
for(ll i=n;i>=1;i--){
if(v.empty()||v.back()<-t[i]){
v.pb(-t[i]);
suf[i]=v.size();
}
else{
ll x=lower_bound(all(v),-t[i])-v.begin();
v[x]=-t[i];
suf[i]=x+1;
}
if(i<n){
suf[i]=max(suf[i],suf[i+1]);
}
}
ll ans=suf[1];
for(ll i=1;i<=n;i++){
ans=max(ans,pre[i]+suf[i+1]);
}
cout<<ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |