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) 2e9 + 9;
int n, x, a[N], dp[N];
pair<int, int> suf[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(dp, dp + n, inf);
for (int i = n - 1; i >= 0; i--) {
int j = lower_bound(dp, dp + n, -a[i]) - dp;
dp[j] = -a[i];
ans = max(ans, j + 1);
suf[i] = {j + 1, a[i]};
}
fill(dp, dp + n, inf);
for (int i = 0; i < n; i++) {
a[i] -= x;
int j = lower_bound(dp, dp + n, a[i]) - dp;
dp[j] = a[i];
if (i + 1 < n) {
int ns = suf[i + 1].second;
int sl = suf[i + 1].first;
j = lower_bound(dp, dp + n, ns) - dp;
j -= 1;
ans = max(ans, j + 1 + sl);
}
}
cout << ans << '\n';
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... |