#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define ll long long
#define int long long
const int N=1e5+5;
void solve(){
int n,x;cin>>n>>x;
vector<int> a(n),pref(n+1),suf(n+1);
for(int i=0;i<n;i++)
cin>>a[i];
vector<int> lis(n,1e10),lds(n,1e10);
int ans=0;
for(int i=0;i<n;i++){
int it=lower_bound(all(lis),a[i])-lis.begin();
if(lis[it]>a[i])
lis[it]=a[i];
pref[i]=it+1;
int A=lower_bound(all(lis),a[i]+x)-lis.begin();
int B=lower_bound(all(lds),a[i]+x)-lds.begin();
if(lds[max(A,B)]>a[i]+x)
lds[max(A,B)]=a[i]+x;
suf[i]=max(A,B)+1;
ans=max(ans,max(suf[i],pref[i]));
}
cout<<ans<<endl;
}
main(){
int T=1;
//cin>>T;
while(T--){
solve();
}
}
/*
12 2
2 3 3 8 1 5 6 7 8 3 5 4
2 1
2 7
3 4
4 7
7 6
5 6
6 8
6 9
7 10
10 11
10 12
*/
Compilation message
glo.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
9296 KB |
Output is correct |
2 |
Correct |
87 ms |
9300 KB |
Output is correct |
3 |
Correct |
87 ms |
9256 KB |
Output is correct |
4 |
Correct |
86 ms |
9300 KB |
Output is correct |
5 |
Correct |
58 ms |
8856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
49 ms |
5016 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |