#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define mp make_pair
#define F first
#define S second
constexpr int maxn = 2e5 + 10;
int n, x;
int t[maxn];
int l[maxn];
vector<int> dp;
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
cin >> n >> x;
for (int i = 0; i < n; i++) cin >> t[i];
vector<int> dp(n, INT_MAX);
int lis = 0;
for (int i = 0; i < n; i++) {
int j = lower_bound(dp.begin(), dp.end(), t[i]) - dp.begin();
dp[j] = t[i];
l[i] = j + 1;
lis = max(lis, l[i]);
}
vector<int> dp2(n, INT_MAX);
for (int i = n - 1; i >= 0; i--) {
int p = lower_bound(dp2.begin(), dp2.end(), x - t[i]) - dp2.begin();
lis = max(lis, l[i] + p);
int ins = lower_bound(dp2.begin(), dp2.end(), -t[i]) - dp2.begin();
dp2[ins] = -t[i];
}
cout << lis << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
5360 KB |
Output is correct |
2 |
Correct |
107 ms |
5396 KB |
Output is correct |
3 |
Correct |
107 ms |
5312 KB |
Output is correct |
4 |
Correct |
104 ms |
5324 KB |
Output is correct |
5 |
Correct |
78 ms |
4496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
1536 KB |
Output is correct |
2 |
Correct |
26 ms |
1464 KB |
Output is correct |
3 |
Correct |
26 ms |
1528 KB |
Output is correct |
4 |
Correct |
18 ms |
1352 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
19 ms |
1356 KB |
Output is correct |
7 |
Correct |
25 ms |
1548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
2840 KB |
Output is correct |
2 |
Correct |
51 ms |
2828 KB |
Output is correct |
3 |
Correct |
104 ms |
5356 KB |
Output is correct |
4 |
Correct |
73 ms |
4508 KB |
Output is correct |
5 |
Correct |
37 ms |
2340 KB |
Output is correct |
6 |
Correct |
66 ms |
4452 KB |
Output is correct |
7 |
Correct |
87 ms |
5116 KB |
Output is correct |
8 |
Correct |
48 ms |
2748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
308 KB |
Output is correct |
17 |
Correct |
0 ms |
312 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
312 KB |
Output is correct |
27 |
Correct |
106 ms |
5360 KB |
Output is correct |
28 |
Correct |
107 ms |
5396 KB |
Output is correct |
29 |
Correct |
107 ms |
5312 KB |
Output is correct |
30 |
Correct |
104 ms |
5324 KB |
Output is correct |
31 |
Correct |
78 ms |
4496 KB |
Output is correct |
32 |
Correct |
26 ms |
1536 KB |
Output is correct |
33 |
Correct |
26 ms |
1464 KB |
Output is correct |
34 |
Correct |
26 ms |
1528 KB |
Output is correct |
35 |
Correct |
18 ms |
1352 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
19 ms |
1356 KB |
Output is correct |
38 |
Correct |
25 ms |
1548 KB |
Output is correct |
39 |
Correct |
52 ms |
2840 KB |
Output is correct |
40 |
Correct |
51 ms |
2828 KB |
Output is correct |
41 |
Correct |
104 ms |
5356 KB |
Output is correct |
42 |
Correct |
73 ms |
4508 KB |
Output is correct |
43 |
Correct |
37 ms |
2340 KB |
Output is correct |
44 |
Correct |
66 ms |
4452 KB |
Output is correct |
45 |
Correct |
87 ms |
5116 KB |
Output is correct |
46 |
Correct |
48 ms |
2748 KB |
Output is correct |
47 |
Correct |
51 ms |
2764 KB |
Output is correct |
48 |
Correct |
55 ms |
2892 KB |
Output is correct |
49 |
Correct |
103 ms |
5420 KB |
Output is correct |
50 |
Correct |
71 ms |
4544 KB |
Output is correct |
51 |
Correct |
56 ms |
3496 KB |
Output is correct |
52 |
Correct |
75 ms |
4608 KB |
Output is correct |
53 |
Correct |
70 ms |
4692 KB |
Output is correct |
54 |
Correct |
94 ms |
5364 KB |
Output is correct |
55 |
Correct |
99 ms |
5436 KB |
Output is correct |