#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#endif
const int inf = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> t(n);
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
vector<int> prefix_dp(n, inf), prefix_lis(n);
for (int i = 0; i < n; ++i) {
int j = (int) distance(prefix_dp.begin(),
lower_bound(
prefix_dp.begin(), prefix_dp.end(),
t[i]
)
);
prefix_dp[j] = t[i];
prefix_lis[i] = j + 1;
}
vector<int> suffix_dp(n, inf), suffix_lis(n);
for (int i = n - 1; i >= 0; --i) {
suffix_lis[i] = (int) distance(suffix_dp.begin(),
lower_bound(
suffix_dp.begin(), suffix_dp.end(),
-(t[i] - x)
)
);
int j = (int) distance(suffix_dp.begin(),
lower_bound(
suffix_dp.begin(), suffix_dp.end(),
-t[i]
)
) ;
suffix_dp[j] = -t[i];
}
int ans = 0;
for (int i = 0; i < n; ++i) {
ans = max(ans, prefix_lis[i] + suffix_lis[i]);
}
cout << ans << '\n';
}
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
4244 KB |
Output is correct |
2 |
Correct |
51 ms |
4192 KB |
Output is correct |
3 |
Correct |
56 ms |
4180 KB |
Output is correct |
4 |
Correct |
50 ms |
4188 KB |
Output is correct |
5 |
Correct |
41 ms |
4240 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
1236 KB |
Output is correct |
2 |
Correct |
13 ms |
1236 KB |
Output is correct |
3 |
Correct |
14 ms |
1236 KB |
Output is correct |
4 |
Correct |
11 ms |
1292 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
10 ms |
1480 KB |
Output is correct |
7 |
Correct |
11 ms |
1792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
2260 KB |
Output is correct |
2 |
Correct |
24 ms |
2720 KB |
Output is correct |
3 |
Correct |
50 ms |
5228 KB |
Output is correct |
4 |
Correct |
37 ms |
4780 KB |
Output is correct |
5 |
Correct |
21 ms |
2772 KB |
Output is correct |
6 |
Correct |
32 ms |
4684 KB |
Output is correct |
7 |
Correct |
40 ms |
4996 KB |
Output is correct |
8 |
Correct |
20 ms |
2696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 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 |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
50 ms |
4244 KB |
Output is correct |
28 |
Correct |
51 ms |
4192 KB |
Output is correct |
29 |
Correct |
56 ms |
4180 KB |
Output is correct |
30 |
Correct |
50 ms |
4188 KB |
Output is correct |
31 |
Correct |
41 ms |
4240 KB |
Output is correct |
32 |
Correct |
14 ms |
1236 KB |
Output is correct |
33 |
Correct |
13 ms |
1236 KB |
Output is correct |
34 |
Correct |
14 ms |
1236 KB |
Output is correct |
35 |
Correct |
11 ms |
1292 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
10 ms |
1480 KB |
Output is correct |
38 |
Correct |
11 ms |
1792 KB |
Output is correct |
39 |
Correct |
25 ms |
2260 KB |
Output is correct |
40 |
Correct |
24 ms |
2720 KB |
Output is correct |
41 |
Correct |
50 ms |
5228 KB |
Output is correct |
42 |
Correct |
37 ms |
4780 KB |
Output is correct |
43 |
Correct |
21 ms |
2772 KB |
Output is correct |
44 |
Correct |
32 ms |
4684 KB |
Output is correct |
45 |
Correct |
40 ms |
4996 KB |
Output is correct |
46 |
Correct |
20 ms |
2696 KB |
Output is correct |
47 |
Correct |
26 ms |
3148 KB |
Output is correct |
48 |
Correct |
24 ms |
3132 KB |
Output is correct |
49 |
Correct |
52 ms |
6088 KB |
Output is correct |
50 |
Correct |
37 ms |
5312 KB |
Output is correct |
51 |
Correct |
30 ms |
4100 KB |
Output is correct |
52 |
Correct |
38 ms |
5448 KB |
Output is correct |
53 |
Correct |
33 ms |
5444 KB |
Output is correct |
54 |
Correct |
51 ms |
6072 KB |
Output is correct |
55 |
Correct |
47 ms |
6164 KB |
Output is correct |