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
using namespace std;
int n,x, arr[200200], p, dp[200200], ans;
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> x;
for(int i = 0; i<n; ++i) cin >> arr[i];
if(x == 0){
for(int i = 0; i<n; ++i){
int idx = lower_bound(dp, dp+p, arr[i]) - dp;
if(idx == p) ++p;
dp[idx] = arr[i];
}
cout << p;
return 0;
}
for(int d = -x; d<=x; ++d){
for(int i = 0; i<n; ++i){
deque<int> dq;
for(int j = i; j<n; ++j){
dq.push_back(arr[j]);
arr[j]+=d;
memset(dp, 0, sizeof(dp)); p = 0;
for(int k = 0; k<n; ++k){
int idx = lower_bound(dp, dp+p, arr[k]) - dp;
if(idx == p) p++;
dp[idx] = arr[k];
}
ans = max(ans, p);
}
for(int j = i; j<n; ++j){
arr[j] = dq.front();
dq.pop_front();
}
}
}
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... |