#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long int ll;
#define pb push_back
int n, ans = 0;
ll arr[N], x, dp[N];
int main(){
cin.tie(0); ios::sync_with_stdio(0);
cin >> n >> x;
for(int i = 1; i <= n; i++) cin >> arr[i];
vector<int> lis(1, 0);
for(int j = 1; j <= n; j++){
int pos = lower_bound(lis.begin(), lis.end(), arr[j]) - lis.begin();
if(pos == int(lis.size())) lis.pb(arr[j]);
else lis[pos] = arr[j];
dp[j] = pos;
}
lis.clear();
lis.pb(-1e9);
for(int i = n; i >= 1; i--){
int new_pos = lower_bound(lis.begin(), lis.end(), -(arr[i] - x)) - lis.begin();
ans = max(ll(dp[i] + new_pos)-1, ll(ans));
int pos = lower_bound(lis.begin(), lis.end(), -arr[i]) - lis.begin();
if(pos == lis.size()) lis.pb(-arr[i]);
else lis[pos] = -arr[i];
}
cout << ans;
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:25:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(pos == lis.size()) lis.pb(-arr[i]);
| ~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
3524 KB |
Output is correct |
2 |
Correct |
60 ms |
3436 KB |
Output is correct |
3 |
Correct |
56 ms |
3436 KB |
Output is correct |
4 |
Correct |
57 ms |
3376 KB |
Output is correct |
5 |
Correct |
35 ms |
3832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
1092 KB |
Output is correct |
2 |
Correct |
13 ms |
1112 KB |
Output is correct |
3 |
Correct |
14 ms |
1068 KB |
Output is correct |
4 |
Correct |
10 ms |
1300 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
10 ms |
1612 KB |
Output is correct |
7 |
Correct |
12 ms |
1488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1868 KB |
Output is correct |
2 |
Correct |
27 ms |
2832 KB |
Output is correct |
3 |
Correct |
55 ms |
5256 KB |
Output is correct |
4 |
Correct |
37 ms |
5060 KB |
Output is correct |
5 |
Correct |
19 ms |
2768 KB |
Output is correct |
6 |
Correct |
34 ms |
4900 KB |
Output is correct |
7 |
Correct |
37 ms |
5580 KB |
Output is correct |
8 |
Correct |
23 ms |
2864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
216 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
63 ms |
3524 KB |
Output is correct |
28 |
Correct |
60 ms |
3436 KB |
Output is correct |
29 |
Correct |
56 ms |
3436 KB |
Output is correct |
30 |
Correct |
57 ms |
3376 KB |
Output is correct |
31 |
Correct |
35 ms |
3832 KB |
Output is correct |
32 |
Correct |
13 ms |
1092 KB |
Output is correct |
33 |
Correct |
13 ms |
1112 KB |
Output is correct |
34 |
Correct |
14 ms |
1068 KB |
Output is correct |
35 |
Correct |
10 ms |
1300 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
10 ms |
1612 KB |
Output is correct |
38 |
Correct |
12 ms |
1488 KB |
Output is correct |
39 |
Correct |
26 ms |
1868 KB |
Output is correct |
40 |
Correct |
27 ms |
2832 KB |
Output is correct |
41 |
Correct |
55 ms |
5256 KB |
Output is correct |
42 |
Correct |
37 ms |
5060 KB |
Output is correct |
43 |
Correct |
19 ms |
2768 KB |
Output is correct |
44 |
Correct |
34 ms |
4900 KB |
Output is correct |
45 |
Correct |
37 ms |
5580 KB |
Output is correct |
46 |
Correct |
23 ms |
2864 KB |
Output is correct |
47 |
Correct |
27 ms |
2808 KB |
Output is correct |
48 |
Correct |
31 ms |
2820 KB |
Output is correct |
49 |
Correct |
64 ms |
5352 KB |
Output is correct |
50 |
Correct |
36 ms |
5112 KB |
Output is correct |
51 |
Correct |
30 ms |
4036 KB |
Output is correct |
52 |
Correct |
43 ms |
5216 KB |
Output is correct |
53 |
Correct |
31 ms |
5204 KB |
Output is correct |
54 |
Correct |
42 ms |
5848 KB |
Output is correct |
55 |
Correct |
51 ms |
5308 KB |
Output is correct |