#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 = lower_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 tt = lower_bound(l2.begin()+1, l2.end(), (b[i]+X)) - l2.begin();
int l = lower_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] = tt-1;
}
ll ans = 1;
for (int i=1;i<N;i++) {
ans = max(ll1[i]+ll2[i], ans);
}
cout << ans;
return 0;
}
/*
8 10
7 3 5 12 2 7 3 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
11744 KB |
Output is correct |
2 |
Correct |
78 ms |
11688 KB |
Output is correct |
3 |
Correct |
72 ms |
11600 KB |
Output is correct |
4 |
Correct |
80 ms |
11600 KB |
Output is correct |
5 |
Correct |
49 ms |
10872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
3164 KB |
Output is correct |
2 |
Correct |
19 ms |
3164 KB |
Output is correct |
3 |
Correct |
20 ms |
3164 KB |
Output is correct |
4 |
Correct |
14 ms |
2908 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
2908 KB |
Output is correct |
7 |
Correct |
17 ms |
3252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
5972 KB |
Output is correct |
2 |
Correct |
35 ms |
5980 KB |
Output is correct |
3 |
Correct |
70 ms |
11600 KB |
Output is correct |
4 |
Correct |
54 ms |
10832 KB |
Output is correct |
5 |
Correct |
37 ms |
5720 KB |
Output is correct |
6 |
Correct |
48 ms |
10332 KB |
Output is correct |
7 |
Correct |
63 ms |
11188 KB |
Output is correct |
8 |
Correct |
34 ms |
5972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
344 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
74 ms |
11744 KB |
Output is correct |
28 |
Correct |
78 ms |
11688 KB |
Output is correct |
29 |
Correct |
72 ms |
11600 KB |
Output is correct |
30 |
Correct |
80 ms |
11600 KB |
Output is correct |
31 |
Correct |
49 ms |
10872 KB |
Output is correct |
32 |
Correct |
18 ms |
3164 KB |
Output is correct |
33 |
Correct |
19 ms |
3164 KB |
Output is correct |
34 |
Correct |
20 ms |
3164 KB |
Output is correct |
35 |
Correct |
14 ms |
2908 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
13 ms |
2908 KB |
Output is correct |
38 |
Correct |
17 ms |
3252 KB |
Output is correct |
39 |
Correct |
37 ms |
5972 KB |
Output is correct |
40 |
Correct |
35 ms |
5980 KB |
Output is correct |
41 |
Correct |
70 ms |
11600 KB |
Output is correct |
42 |
Correct |
54 ms |
10832 KB |
Output is correct |
43 |
Correct |
37 ms |
5720 KB |
Output is correct |
44 |
Correct |
48 ms |
10332 KB |
Output is correct |
45 |
Correct |
63 ms |
11188 KB |
Output is correct |
46 |
Correct |
34 ms |
5972 KB |
Output is correct |
47 |
Correct |
36 ms |
5968 KB |
Output is correct |
48 |
Correct |
43 ms |
6020 KB |
Output is correct |
49 |
Correct |
74 ms |
11600 KB |
Output is correct |
50 |
Correct |
49 ms |
10968 KB |
Output is correct |
51 |
Correct |
40 ms |
8272 KB |
Output is correct |
52 |
Correct |
54 ms |
11084 KB |
Output is correct |
53 |
Correct |
59 ms |
10960 KB |
Output is correct |
54 |
Correct |
73 ms |
11744 KB |
Output is correct |
55 |
Correct |
188 ms |
11744 KB |
Output is correct |