This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 5e5 + 10;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e9;
ll dp[maxn5], a[maxn5];
int lastof[maxn5];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n, x; cin >> n >> x;
fill(dp, dp + n + 10, inf);
int ans = 0;
for(int i = 0; i < n; i++){
cin >> a[i];
int p = lower_bound(dp + 1, dp + n + 5, a[i]) - dp;
lastof[i] = p;
dp[p] = a[i];
ans = max(ans, p);
}
fill(dp, dp + n + 10, inf);
for(int i = n - 1; i >= 0; i--){
int p = lower_bound(dp + 1, dp + n + 5, -1 * a[i] + x) - dp;
ans = max(ans, p + lastof[i] - 1);
p = lower_bound(dp + 1, dp + n + 5, -1 * a[i]) - dp;
dp[p] = -1 * a[i];
}
cout << ans << endl;
}
# | 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... |