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 MAXN = 2e5 + 5;
const int INF = 1e9;
int n, x, sz, ans;
int a[MAXN];
int lds[MAXN], dp[MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for(int i = 1; i <= n; i++)
{
cin >> a[i];
dp[i] = -INF;
}
dp[0] = INF;
for(int i = n; i >= 1; i--)
{
int id = lower_bound(dp, dp + sz + 1, a[i], greater <int> ()) - dp;
lds[i] = id;
dp[id] = max(dp[id], a[i]);
sz = max(sz, id);
}
ans = sz;
sz = 0;
for(int i = 1; i <= n; i++)
{
dp[i] = INF;
}
dp[0] = -INF;
for(int i = 1; i <= n; i++)
{
int id = lower_bound(dp, dp + sz + 1, a[i]) - dp;
int zz = upper_bound(dp, dp + sz + 1, a[i] + x - 1) - dp - 1;
ans = max(ans, zz + lds[i]);
dp[id] = min(dp[id], a[i]);
sz = max(sz, id);
}
cout << ans << '\n';
}
# | 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... |