#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
const ll inf = 1e10;
int main()
{
ll N,X;
cin>>N>>X;
vector<ll> a(N+10);
vector<ll> b(N+10);
for (int i=1;i<=N;i++) {
cin>>a[i];
b[N+1-i] = -a[i];
}
vector<ll> l1(N+10, inf);
vector<ll> ll1(N+10,inf);
l1[0] = -inf;
for (int i=1;i<=N;i++) {
int l = upper_bound(l1.begin()+1, l1.end(), a[i]) - (l1.begin());
if (l1[l-1] < a[i] && a[i] < l1[l]) {
l1[l] = a[i];
}
ll1[i] = l;
}
vector<ll> l2(N+10, inf);
vector<ll> ll2(N+10,inf);
l2[0] = -inf;
for (int i=1;i<=N;i++) {
int l = upper_bound(l2.begin()+1, l2.end(), b[i]) - (l2.begin());
if (l2[l-1] < b[i] && b[i] < l2[l]) {
l2[l] = b[i];
}
ll2[N+1-i] = l;
if (N+1-i<N) {
ll2[N+1-i] = max(ll2[N+1-i+1], (long long)l);
}
}
ll ans = 0;
for (int i=1;i<N;i++) {
if (a[i]-X+1<=a[i+1]) {
//cout << ans;
ans = max(ans, ll1[i]+ll2[i+1]);
}
}
cout << ans;
return 0;
}
/*
8 10
7 3 5 12 2 7 3 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
11748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
3244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
6068 KB |
Output is correct |
2 |
Correct |
43 ms |
6088 KB |
Output is correct |
3 |
Correct |
99 ms |
11604 KB |
Output is correct |
4 |
Correct |
49 ms |
10836 KB |
Output is correct |
5 |
Correct |
25 ms |
5580 KB |
Output is correct |
6 |
Correct |
43 ms |
10324 KB |
Output is correct |
7 |
Correct |
69 ms |
11220 KB |
Output is correct |
8 |
Correct |
33 ms |
5968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |