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;
#define int long long
const int inf = 1e18;
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, x; cin >> n >> x;
vector<int> a(n), L(n), R(n);
for (int i = 0; i < n; i++) cin >> a[i];
vector<int> dp(n, inf);
int mx = 0;
for (int i = 0; i < n; i++) {
int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
dp[j] = a[i];
L[i] = j + 1;
}
fill(dp.begin(), dp.end(), inf);
for (int i = n - 1; i >= 0; i--) {
int pos = lower_bound(dp.begin(), dp.end(), -(a[i] - x)) - dp.begin();
R[i] = pos;
pos = lower_bound(dp.begin(), dp.end(), -a[i]) - dp.begin();
dp[pos] = -a[i];
}
for (int i = 0; i < n; i++) {
mx = max(mx, L[i] + R[i]);
}
cout << mx << "\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... |