#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define fi first
#define se second
using namespace std;
const int N = 2e5 + 4;
const int oo = 1e18;
const int mod = (1 << 9);
int t, n, q, m, k, ans = 0, a[N], dp[N], f[N]{};
vector<int>v;
void solve(){
cin >> n >> k;
for (int i = 0; i < n; i++)cin >> a[i], dp[i] = oo;
for (int i = 0; i < n; i++){
m = lower_bound(dp, dp + n, a[i]) - dp;
f[i] = m + 1;
dp[m] = a[i];
ans = max(ans, f[i]);
}
for (int i = 0; i < n; i++)dp[i] = oo;
for (int i = n - 1; i >= 0; i--){
m = lower_bound(dp, dp + n, k - a[i]) - dp;
ans = max(ans, f[i] + m);
m = lower_bound(dp, dp + n, -a[i]) - dp;
dp[m] = -a[i];
}
cout << ans;
}
main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("prime.inp", "r", stdin); freopen("prime.out", "w", stdout);
t = 1;
//cin >> t;
while (t--)solve();
return 0;
}
Compilation message
glo.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
404 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
404 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
404 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
6284 KB |
Output is correct |
2 |
Correct |
49 ms |
6228 KB |
Output is correct |
3 |
Correct |
46 ms |
6412 KB |
Output is correct |
4 |
Correct |
48 ms |
6228 KB |
Output is correct |
5 |
Correct |
33 ms |
5712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
1880 KB |
Output is correct |
2 |
Correct |
10 ms |
2132 KB |
Output is correct |
3 |
Correct |
10 ms |
2136 KB |
Output is correct |
4 |
Correct |
8 ms |
1884 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
1940 KB |
Output is correct |
7 |
Correct |
10 ms |
1896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
3684 KB |
Output is correct |
2 |
Correct |
20 ms |
3572 KB |
Output is correct |
3 |
Correct |
43 ms |
7004 KB |
Output is correct |
4 |
Correct |
31 ms |
6236 KB |
Output is correct |
5 |
Correct |
18 ms |
3164 KB |
Output is correct |
6 |
Correct |
28 ms |
5980 KB |
Output is correct |
7 |
Correct |
32 ms |
6740 KB |
Output is correct |
8 |
Correct |
19 ms |
3672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 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 |
404 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
468 KB |
Output is correct |
14 |
Correct |
0 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 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 |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
49 ms |
6284 KB |
Output is correct |
28 |
Correct |
49 ms |
6228 KB |
Output is correct |
29 |
Correct |
46 ms |
6412 KB |
Output is correct |
30 |
Correct |
48 ms |
6228 KB |
Output is correct |
31 |
Correct |
33 ms |
5712 KB |
Output is correct |
32 |
Correct |
12 ms |
1880 KB |
Output is correct |
33 |
Correct |
10 ms |
2132 KB |
Output is correct |
34 |
Correct |
10 ms |
2136 KB |
Output is correct |
35 |
Correct |
8 ms |
1884 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
8 ms |
1940 KB |
Output is correct |
38 |
Correct |
10 ms |
1896 KB |
Output is correct |
39 |
Correct |
21 ms |
3684 KB |
Output is correct |
40 |
Correct |
20 ms |
3572 KB |
Output is correct |
41 |
Correct |
43 ms |
7004 KB |
Output is correct |
42 |
Correct |
31 ms |
6236 KB |
Output is correct |
43 |
Correct |
18 ms |
3164 KB |
Output is correct |
44 |
Correct |
28 ms |
5980 KB |
Output is correct |
45 |
Correct |
32 ms |
6740 KB |
Output is correct |
46 |
Correct |
19 ms |
3672 KB |
Output is correct |
47 |
Correct |
23 ms |
3676 KB |
Output is correct |
48 |
Correct |
21 ms |
3676 KB |
Output is correct |
49 |
Correct |
45 ms |
7004 KB |
Output is correct |
50 |
Correct |
32 ms |
6232 KB |
Output is correct |
51 |
Correct |
32 ms |
4700 KB |
Output is correct |
52 |
Correct |
35 ms |
6224 KB |
Output is correct |
53 |
Correct |
35 ms |
6156 KB |
Output is correct |
54 |
Correct |
36 ms |
6996 KB |
Output is correct |
55 |
Correct |
40 ms |
7000 KB |
Output is correct |