이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,X;
cin>>N>>X;
ll arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i];
}
//we can prove that it is always optimal to subtract x from prefix [0,i] because obviously we want the first few elements as small as possible, it will do no worse than subtracting x from [j,i]
//since we are subtracting from the prefix, we should obviously subtract as much as possible which is x
vector<ll> v(N,1e18);
ll longestprefix[N];
ll ans = 0;
for(ll i = 0;i < N;i++){
auto it = lower_bound(v.begin(),v.end(),arr[i]);
v[it - v.begin()] = arr[i];
longestprefix[i] = it - v.begin() + 1;
ans = max(ans,longestprefix[i]);
}
v.clear();
v = vector<ll>(N, 1e18);
for(ll i = N - 1;i >= 0;i--){
ll pos = lower_bound(v.begin(),v.end(),-arr[i] + X) - v.begin();
ans = max(ans,longestprefix[i] + pos);
ll insert_pos = lower_bound(v.begin(),v.end(),-arr[i]) - v.begin();
v[insert_pos] = -arr[i];
}
cout<<ans<<'\n';
}
# | 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... |