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 fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME (1.0 * clock() / CLOCKS_PER_SEC)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 2e5 + 5;
const int oo = 1e9, mod = 1e9 + 7;
int n, m, k, x, f[2][N], ans=0, a[N];
string s;
vector<int> arr;
void process() {
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[0][i] = f[1][i] = oo;
}
f[0][0] = f[1][0] = -oo;
for (int i = 2; i <= n; i++) {
int 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);
k = lower_bound(f[1] + 1, f[1] + n + 1, a[i]) - f[1];
f[1][k] = a[i];
ans = max(ans, k);
}
cout << ans << '\n';
return;
}
signed main() {
cin.tie(0)->sync_with_stdio(false);
//freopen(".inp", "r", stdin);
//freopen(".out", "w", stdout);
process();
cerr << "Time elapsed: " << __TIME << " s.\n";
return 0;
}
// dont stop
# | 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... |