#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, x;
cin >> n >> x;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
vector<int> prefix(n), suffix(n), dp;
int j;
for(int i = 0; i < n; i++){
j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
prefix[i] = j+1;
a[i] -= x;
j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(j == dp.size()){
dp.push_back(a[i]);
}
else{
dp[j] = a[i];
}
}
for(int i = 0; i < n; i++){
a[i] *= -1;
}
dp.clear();
for(int i = n-1; i >= 0; i--){
a[i] -= x;
j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(j == dp.size()){
dp.push_back(a[i]);
}
else{
dp[j] = a[i];
}
suffix[i] = j+1;
}
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, prefix[i] + suffix[i] - 1);
}
cout << ans << '\n';
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:23:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(j == dp.size()){
| ~~^~~~~~~~~~~~
glo.cpp:37:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(j == dp.size()){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
2652 KB |
Output is correct |
2 |
Correct |
46 ms |
4736 KB |
Output is correct |
3 |
Correct |
48 ms |
4696 KB |
Output is correct |
4 |
Correct |
51 ms |
4564 KB |
Output is correct |
5 |
Correct |
22 ms |
4452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
856 KB |
Output is correct |
2 |
Correct |
11 ms |
1372 KB |
Output is correct |
3 |
Correct |
11 ms |
1368 KB |
Output is correct |
4 |
Correct |
6 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1448 KB |
Output is correct |
7 |
Correct |
9 ms |
1628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1624 KB |
Output is correct |
2 |
Correct |
19 ms |
2396 KB |
Output is correct |
3 |
Correct |
44 ms |
4696 KB |
Output is correct |
4 |
Correct |
23 ms |
4576 KB |
Output is correct |
5 |
Correct |
12 ms |
2528 KB |
Output is correct |
6 |
Correct |
26 ms |
4528 KB |
Output is correct |
7 |
Correct |
23 ms |
5088 KB |
Output is correct |
8 |
Correct |
15 ms |
2632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 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 |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
46 ms |
2652 KB |
Output is correct |
28 |
Correct |
46 ms |
4736 KB |
Output is correct |
29 |
Correct |
48 ms |
4696 KB |
Output is correct |
30 |
Correct |
51 ms |
4564 KB |
Output is correct |
31 |
Correct |
22 ms |
4452 KB |
Output is correct |
32 |
Correct |
10 ms |
856 KB |
Output is correct |
33 |
Correct |
11 ms |
1372 KB |
Output is correct |
34 |
Correct |
11 ms |
1368 KB |
Output is correct |
35 |
Correct |
6 ms |
1372 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
1448 KB |
Output is correct |
38 |
Correct |
9 ms |
1628 KB |
Output is correct |
39 |
Correct |
19 ms |
1624 KB |
Output is correct |
40 |
Correct |
19 ms |
2396 KB |
Output is correct |
41 |
Correct |
44 ms |
4696 KB |
Output is correct |
42 |
Correct |
23 ms |
4576 KB |
Output is correct |
43 |
Correct |
12 ms |
2528 KB |
Output is correct |
44 |
Correct |
26 ms |
4528 KB |
Output is correct |
45 |
Correct |
23 ms |
5088 KB |
Output is correct |
46 |
Correct |
15 ms |
2632 KB |
Output is correct |
47 |
Correct |
23 ms |
2508 KB |
Output is correct |
48 |
Correct |
22 ms |
2396 KB |
Output is correct |
49 |
Correct |
45 ms |
4680 KB |
Output is correct |
50 |
Correct |
22 ms |
4572 KB |
Output is correct |
51 |
Correct |
21 ms |
3552 KB |
Output is correct |
52 |
Correct |
22 ms |
4592 KB |
Output is correct |
53 |
Correct |
21 ms |
4576 KB |
Output is correct |
54 |
Correct |
23 ms |
5204 KB |
Output is correct |
55 |
Correct |
35 ms |
4692 KB |
Output is correct |