#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define F first
#define S second
#define pb push_back
#define md ((b + e) >> 1)
#define lc (ind << 1)
#define rc (lc | 1)
const ll N = 2e5 + 10;
const ll M = 50;
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 10;
int n, X, a[N], l[N], r[N], f[N], ans;
int main() {
cin >> n >> X;
int len = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
int p = lower_bound(l, l + len, a[i]) - l;
l[p] = a[i];
len = max(len, p + 1);
f[i] = p + 1;
}
ans = f[n - 1];
len = 0;
for (int i = n - 1; i >= 0; i--){
a[i] *= -1;
int p = upper_bound(r, r + len, a[i] - 1) - r;
ans = max(ans, f[i] + p);
a[i] -= X;
p = lower_bound(r, r + len, a[i]) - r;
r[p] = a[i];
len = max(len, p + 1);
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
2924 KB |
Output is correct |
2 |
Correct |
117 ms |
3052 KB |
Output is correct |
3 |
Correct |
116 ms |
3052 KB |
Output is correct |
4 |
Correct |
119 ms |
3052 KB |
Output is correct |
5 |
Correct |
75 ms |
3820 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
1004 KB |
Output is correct |
2 |
Correct |
29 ms |
1260 KB |
Output is correct |
3 |
Correct |
28 ms |
1260 KB |
Output is correct |
4 |
Correct |
19 ms |
1260 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
18 ms |
1260 KB |
Output is correct |
7 |
Correct |
27 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
1856 KB |
Output is correct |
2 |
Correct |
54 ms |
2028 KB |
Output is correct |
3 |
Correct |
108 ms |
3052 KB |
Output is correct |
4 |
Correct |
74 ms |
3820 KB |
Output is correct |
5 |
Correct |
36 ms |
2028 KB |
Output is correct |
6 |
Correct |
68 ms |
3692 KB |
Output is correct |
7 |
Correct |
90 ms |
3692 KB |
Output is correct |
8 |
Correct |
53 ms |
2156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
0 ms |
364 KB |
Output is correct |
12 |
Correct |
0 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
0 ms |
364 KB |
Output is correct |
18 |
Correct |
0 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
1 ms |
364 KB |
Output is correct |
24 |
Correct |
1 ms |
364 KB |
Output is correct |
25 |
Correct |
1 ms |
492 KB |
Output is correct |
26 |
Correct |
1 ms |
364 KB |
Output is correct |
27 |
Correct |
117 ms |
2924 KB |
Output is correct |
28 |
Correct |
117 ms |
3052 KB |
Output is correct |
29 |
Correct |
116 ms |
3052 KB |
Output is correct |
30 |
Correct |
119 ms |
3052 KB |
Output is correct |
31 |
Correct |
75 ms |
3820 KB |
Output is correct |
32 |
Correct |
29 ms |
1004 KB |
Output is correct |
33 |
Correct |
29 ms |
1260 KB |
Output is correct |
34 |
Correct |
28 ms |
1260 KB |
Output is correct |
35 |
Correct |
19 ms |
1260 KB |
Output is correct |
36 |
Correct |
1 ms |
364 KB |
Output is correct |
37 |
Correct |
18 ms |
1260 KB |
Output is correct |
38 |
Correct |
27 ms |
1260 KB |
Output is correct |
39 |
Correct |
55 ms |
1856 KB |
Output is correct |
40 |
Correct |
54 ms |
2028 KB |
Output is correct |
41 |
Correct |
108 ms |
3052 KB |
Output is correct |
42 |
Correct |
74 ms |
3820 KB |
Output is correct |
43 |
Correct |
36 ms |
2028 KB |
Output is correct |
44 |
Correct |
68 ms |
3692 KB |
Output is correct |
45 |
Correct |
90 ms |
3692 KB |
Output is correct |
46 |
Correct |
53 ms |
2156 KB |
Output is correct |
47 |
Correct |
57 ms |
2156 KB |
Output is correct |
48 |
Correct |
60 ms |
2156 KB |
Output is correct |
49 |
Correct |
117 ms |
3820 KB |
Output is correct |
50 |
Correct |
76 ms |
3820 KB |
Output is correct |
51 |
Correct |
57 ms |
3308 KB |
Output is correct |
52 |
Correct |
82 ms |
4076 KB |
Output is correct |
53 |
Correct |
72 ms |
3948 KB |
Output is correct |
54 |
Correct |
96 ms |
4588 KB |
Output is correct |
55 |
Correct |
106 ms |
3820 KB |
Output is correct |