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 ll = long long;
using namespace std;
const int N = 2e5 + 1, mod = 1e9 + 7;
int n, x, ans = 0, a[N], f[2][N];
int main() { cin.tie(0)->sync_with_stdio(0);
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[0][i] = f[1][i] = INT_MAX;
}
f[0][0] = f[1][0] = -INT_MAX;
for (int i = 2; i <= n; i++) {
int k = lower_bound(f[1] + 1, f[1] + n + 1, a[i]) - f[1];
f[1][k] = a[i];
ans = max(ans, k);
k = lower_bound(f[0] + 1, f[0] + n + 1, a[i - 1] - x) - f[0];
f[0][k] = a[i - 1] - x;
f[1][k] = min(f[1][k], f[0][k]);
ans = max(ans, k);
}
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... |