#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
int main(){
fast;
long long int n, x;
cin >> n >> x;
vector<int> a(n);
for(int i = 0; i < n; ++i)
cin >> a[i];
int left_dp[n + 1], right_dp[n + 1];
vector<int> lis;
left_dp[0] = 1;
lis.push_back(a[0]);
for(int i = 1; i < n; ++i){
if(a[i] > lis.back()){
lis.push_back(a[i]);
left_dp[i] = lis.size();
}
else{
int low = 0, high = lis.size() - 1, ans = -1;
while(low <= high){
int mid = (low + high) / 2;
if(lis[mid] >= a[i]){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans != -1)
lis[ans] = a[i];
left_dp[i] = ans + 1;
}
}
right_dp[n - 1] = 1;
lis.clear();
lis.push_back(a[n - 1]);
for(int i = n - 2; i >= 0; --i){
if(a[i] < lis.back()){
lis.push_back(a[i]);
right_dp[i] = lis.size();
}
else{
int low = 0, ans = -1, high = lis.size();
while(low <= high){
int mid = (low + high) / 2;
if(lis[mid] <= a[i] - x){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans == -1)
ans = lis.size();
right_dp[i] = ans + 1;
low = 0, ans = -1, high = lis.size();
while(low <= high){
int mid = (low + high) / 2;
if(lis[mid] <= a[i]){
ans = mid;
high = mid - 1;
}
else
low = mid + 1;
}
if(ans != -1)
lis[ans] = a[i];
}
}
int mx = 0;
for(int i = 0; i < n; ++i)
mx = max(mx, left_dp[i] + right_dp[i] - 1);
cout << mx << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
2668 KB |
Output is correct |
2 |
Correct |
56 ms |
2688 KB |
Output is correct |
3 |
Correct |
56 ms |
2668 KB |
Output is correct |
4 |
Correct |
56 ms |
2668 KB |
Output is correct |
5 |
Correct |
27 ms |
3224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
876 KB |
Output is correct |
2 |
Correct |
13 ms |
876 KB |
Output is correct |
3 |
Correct |
13 ms |
876 KB |
Output is correct |
4 |
Correct |
7 ms |
1132 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
7 ms |
1388 KB |
Output is correct |
7 |
Correct |
12 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1516 KB |
Output is correct |
2 |
Correct |
27 ms |
2560 KB |
Output is correct |
3 |
Correct |
50 ms |
4588 KB |
Output is correct |
4 |
Correct |
28 ms |
4332 KB |
Output is correct |
5 |
Correct |
14 ms |
2416 KB |
Output is correct |
6 |
Correct |
23 ms |
4332 KB |
Output is correct |
7 |
Correct |
30 ms |
4972 KB |
Output is correct |
8 |
Correct |
21 ms |
2540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
364 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
57 ms |
2668 KB |
Output is correct |
28 |
Correct |
56 ms |
2688 KB |
Output is correct |
29 |
Correct |
56 ms |
2668 KB |
Output is correct |
30 |
Correct |
56 ms |
2668 KB |
Output is correct |
31 |
Correct |
27 ms |
3224 KB |
Output is correct |
32 |
Correct |
15 ms |
876 KB |
Output is correct |
33 |
Correct |
13 ms |
876 KB |
Output is correct |
34 |
Correct |
13 ms |
876 KB |
Output is correct |
35 |
Correct |
7 ms |
1132 KB |
Output is correct |
36 |
Correct |
0 ms |
364 KB |
Output is correct |
37 |
Correct |
7 ms |
1388 KB |
Output is correct |
38 |
Correct |
12 ms |
1408 KB |
Output is correct |
39 |
Correct |
25 ms |
1516 KB |
Output is correct |
40 |
Correct |
27 ms |
2560 KB |
Output is correct |
41 |
Correct |
50 ms |
4588 KB |
Output is correct |
42 |
Correct |
28 ms |
4332 KB |
Output is correct |
43 |
Correct |
14 ms |
2416 KB |
Output is correct |
44 |
Correct |
23 ms |
4332 KB |
Output is correct |
45 |
Correct |
30 ms |
4972 KB |
Output is correct |
46 |
Correct |
21 ms |
2540 KB |
Output is correct |
47 |
Correct |
28 ms |
2540 KB |
Output is correct |
48 |
Correct |
29 ms |
2540 KB |
Output is correct |
49 |
Correct |
58 ms |
4716 KB |
Output is correct |
50 |
Correct |
28 ms |
4332 KB |
Output is correct |
51 |
Correct |
23 ms |
3436 KB |
Output is correct |
52 |
Correct |
28 ms |
4460 KB |
Output is correct |
53 |
Correct |
24 ms |
4460 KB |
Output is correct |
54 |
Correct |
32 ms |
5228 KB |
Output is correct |
55 |
Correct |
46 ms |
4716 KB |
Output is correct |