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 mp make_pair
#define pb push_back
#define fi first
#define se second
template<typename T> bool chkmin(T &a, T b){return b < a ? a = b, 1 : 0;}
template<typename T> bool chkmax(T &a, T b){return b > a ? a = b, 1 : 0;}
const int inf = 2e9 + 10, MAXN = 2e5 + 10;
int n, x, a[MAXN], f[MAXN], L[MAXN], R[MAXN];
int main(){
// input
scanf("%d %d", &n, &x);
for(int i = 1; i <= n; i++)
scanf("%d", &a[i]);
// L
for(int i = 1; i <= n; i++)
f[i] = inf;
for(int i = 1; i <= n; i++){
L[i] = lower_bound(f + 1, f + 1 + n, a[i] + x) - f;
int j = lower_bound(f + 1, f + 1 + n, a[i]) - f;
f[j] = a[i];
}
// R
for(int i = 1; i <= n; i++)
f[i] = inf;
for(int i = n; i >= 1; i--){ // LDS of reverse = LIS of - reverse
R[i] = lower_bound(f + 1, f + 1 + n, -a[i]) - f;
f[R[i]] = -a[i];
}
// ans
int ans = 0;
for(int i = 1; i <= n; i++)
chkmax(ans, L[i] + R[i] - 1);
printf("%d\n", ans);
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d %d", &n, &x);
| ~~~~~^~~~~~~~~~~~~~~~~
glo.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |