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>
using namespace std;
const int N = (int) 2e5 + 9;
const int inf = (int) 1e9 + 9;
int n, x, a[N], lis_dp[N], brute_dp[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> x;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 1;
fill(lis_dp, lis_dp + n, inf);
for (int i = 0; i < n; i++) {
int j = lower_bound(lis_dp, lis_dp + n, a[i]) - lis_dp;
lis_dp[j] = a[i];
ans = max(ans, j + 1);
}
if (x == 0) {
cout << ans << '\n';
return 0;
}
//if (n * 1LL * n * 1LL * n * 2LL * x <= (int) 2e8) {
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
for (int k = -x; k <= x; k++) {
fill(brute_dp, brute_dp + n, inf);
for (int ii = 0; ii < n; ii++) {
int jj = lower_bound(brute_dp, brute_dp + n, a[ii] + (i <= ii && ii <= j) * x) - brute_dp;
brute_dp[jj] = a[ii] + (i <= ii && ii <= j) * x;
ans = max(ans, jj + 1);
}
}
}
}
cout << ans << '\n';
//return 0;
//}
return 0;
}
# | 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... |