#include <bits/stdc++.h>
#define pb push_back
#define lwb lower_bound
#define all(x) (x).begin(), (x).end()
using namespace std;
const int N = 2e5 + 3;
int n, x, res, dp[N], a[N];
vector<int> lis;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n >> x;
for(int i = 1; i <= n; ++i){
cin >> a[i];
int j = lwb(all(lis), a[i]) - lis.begin();
dp[i] = j + 1;
if(j == lis.size()) lis.pb(a[i]);
else lis[j] = a[i];
}
lis.clear();
for(int i = n; i >= 1; --i){
int j = lwb(all(lis), -a[i]) - lis.begin();
res = max(res, dp[i] + j);
j = lwb(all(lis), -a[i] - x) - lis.begin();
if(j == lis.size()) lis.pb(-a[i]- x);
else lis[j] = -a[i] - x;
}
cout << res;
return 0;
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:17:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(j == lis.size()) lis.pb(a[i]);
| ~~^~~~~~~~~~~~~
glo.cpp:25:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(j == lis.size()) lis.pb(-a[i]- x);
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
1876 KB |
Output is correct |
2 |
Correct |
43 ms |
1880 KB |
Output is correct |
3 |
Correct |
51 ms |
1876 KB |
Output is correct |
4 |
Correct |
43 ms |
1876 KB |
Output is correct |
5 |
Correct |
22 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
724 KB |
Output is correct |
2 |
Correct |
13 ms |
724 KB |
Output is correct |
3 |
Correct |
14 ms |
672 KB |
Output is correct |
4 |
Correct |
9 ms |
860 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
8 ms |
1236 KB |
Output is correct |
7 |
Correct |
11 ms |
1108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
25 ms |
1124 KB |
Output is correct |
2 |
Correct |
21 ms |
1124 KB |
Output is correct |
3 |
Correct |
37 ms |
1760 KB |
Output is correct |
4 |
Correct |
21 ms |
2396 KB |
Output is correct |
5 |
Correct |
16 ms |
1368 KB |
Output is correct |
6 |
Correct |
23 ms |
2260 KB |
Output is correct |
7 |
Correct |
33 ms |
2232 KB |
Output is correct |
8 |
Correct |
22 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
328 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
50 ms |
1876 KB |
Output is correct |
28 |
Correct |
43 ms |
1880 KB |
Output is correct |
29 |
Correct |
51 ms |
1876 KB |
Output is correct |
30 |
Correct |
43 ms |
1876 KB |
Output is correct |
31 |
Correct |
22 ms |
2388 KB |
Output is correct |
32 |
Correct |
13 ms |
724 KB |
Output is correct |
33 |
Correct |
13 ms |
724 KB |
Output is correct |
34 |
Correct |
14 ms |
672 KB |
Output is correct |
35 |
Correct |
9 ms |
860 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
8 ms |
1236 KB |
Output is correct |
38 |
Correct |
11 ms |
1108 KB |
Output is correct |
39 |
Correct |
25 ms |
1124 KB |
Output is correct |
40 |
Correct |
21 ms |
1124 KB |
Output is correct |
41 |
Correct |
37 ms |
1760 KB |
Output is correct |
42 |
Correct |
21 ms |
2396 KB |
Output is correct |
43 |
Correct |
16 ms |
1368 KB |
Output is correct |
44 |
Correct |
23 ms |
2260 KB |
Output is correct |
45 |
Correct |
33 ms |
2232 KB |
Output is correct |
46 |
Correct |
22 ms |
1092 KB |
Output is correct |
47 |
Correct |
21 ms |
2004 KB |
Output is correct |
48 |
Correct |
21 ms |
2052 KB |
Output is correct |
49 |
Correct |
45 ms |
3800 KB |
Output is correct |
50 |
Correct |
22 ms |
3448 KB |
Output is correct |
51 |
Correct |
20 ms |
2832 KB |
Output is correct |
52 |
Correct |
26 ms |
3608 KB |
Output is correct |
53 |
Correct |
20 ms |
3592 KB |
Output is correct |
54 |
Correct |
35 ms |
4232 KB |
Output is correct |
55 |
Correct |
46 ms |
3812 KB |
Output is correct |