#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 3;
int ar[N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, g; cin >> n >> g;
for(int i=1; i<=n; ++i) cin >> ar[i];
int res = 1;
int dp[n+1];
dp[0] = 0;
vector<int> lis;
for(int i=1; i<=n; ++i) {
auto t = lower_bound(lis.begin(), lis.end(), ar[i]);
dp[i] = t - lis.begin() + 1;
if(t == lis.end()) lis.emplace_back(ar[i]);
else *t = ar[i];
//cout << dp[i] << " \n"[i == n];
}
res = lis.size();
lis.clear();
for(int i=n; i>=1; --i) {
int x = lower_bound(lis.begin(), lis.end(), -ar[i] + 2*g) - lis.begin();
//cout << "I: " << i << " => ";
//for(auto x : lis) cout << x << ' ';
//cout << " | " << x << endl;
res = max(res, dp[i] + x );
int y = lower_bound(lis.begin(), lis.end(), -ar[i] + g) - lis.begin();
if(y == lis.size()) lis.emplace_back(-ar[i] + g);
else lis[y] = -ar[i] + g;
}
cout << res << '\n';
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:37:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | if(y == lis.size()) lis.emplace_back(-ar[i] + g);
| ~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
388 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
388 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
480 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
1976 KB |
Output is correct |
2 |
Correct |
37 ms |
2128 KB |
Output is correct |
3 |
Correct |
41 ms |
1872 KB |
Output is correct |
4 |
Correct |
37 ms |
1996 KB |
Output is correct |
5 |
Correct |
21 ms |
3020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1104 KB |
Output is correct |
2 |
Correct |
9 ms |
1104 KB |
Output is correct |
3 |
Correct |
9 ms |
860 KB |
Output is correct |
4 |
Correct |
5 ms |
848 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
6 ms |
1360 KB |
Output is correct |
7 |
Correct |
8 ms |
1352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1260 KB |
Output is correct |
2 |
Correct |
20 ms |
1840 KB |
Output is correct |
3 |
Correct |
33 ms |
1884 KB |
Output is correct |
4 |
Correct |
21 ms |
3296 KB |
Output is correct |
5 |
Correct |
10 ms |
2128 KB |
Output is correct |
6 |
Correct |
20 ms |
3540 KB |
Output is correct |
7 |
Correct |
26 ms |
4308 KB |
Output is correct |
8 |
Correct |
15 ms |
1104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
368 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
388 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
480 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
36 ms |
1976 KB |
Output is correct |
28 |
Correct |
37 ms |
2128 KB |
Output is correct |
29 |
Correct |
41 ms |
1872 KB |
Output is correct |
30 |
Correct |
37 ms |
1996 KB |
Output is correct |
31 |
Correct |
21 ms |
3020 KB |
Output is correct |
32 |
Correct |
12 ms |
1104 KB |
Output is correct |
33 |
Correct |
9 ms |
1104 KB |
Output is correct |
34 |
Correct |
9 ms |
860 KB |
Output is correct |
35 |
Correct |
5 ms |
848 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
6 ms |
1360 KB |
Output is correct |
38 |
Correct |
8 ms |
1352 KB |
Output is correct |
39 |
Correct |
17 ms |
1260 KB |
Output is correct |
40 |
Correct |
20 ms |
1840 KB |
Output is correct |
41 |
Correct |
33 ms |
1884 KB |
Output is correct |
42 |
Correct |
21 ms |
3296 KB |
Output is correct |
43 |
Correct |
10 ms |
2128 KB |
Output is correct |
44 |
Correct |
20 ms |
3540 KB |
Output is correct |
45 |
Correct |
26 ms |
4308 KB |
Output is correct |
46 |
Correct |
15 ms |
1104 KB |
Output is correct |
47 |
Correct |
21 ms |
1608 KB |
Output is correct |
48 |
Correct |
18 ms |
2128 KB |
Output is correct |
49 |
Correct |
42 ms |
3812 KB |
Output is correct |
50 |
Correct |
30 ms |
3796 KB |
Output is correct |
51 |
Correct |
19 ms |
3028 KB |
Output is correct |
52 |
Correct |
21 ms |
3284 KB |
Output is correct |
53 |
Correct |
20 ms |
3796 KB |
Output is correct |
54 |
Correct |
25 ms |
3788 KB |
Output is correct |
55 |
Correct |
34 ms |
3924 KB |
Output is correct |