#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, x; cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
vector<int> d(n + 1, INT32_MAX);
d[0] = INT32_MIN;
vector<pair<int, int>> at(n + 1, {0, INT32_MIN});
for (int i = 0; i < n; ++i) {
int l = upper_bound(d.begin(), d.end(), a[i] - x) - d.begin();
if (d[l - 1] < a[i] - x) {
d[l] = a[i] - x;
at[i + 1] = {l, a[i] - x};
}
}
int ans = at[n].first;
d.assign(n + 1, INT32_MAX);
d[0] = INT32_MIN;
for (int i = n - 1; i >= 0; --i) {
int l = upper_bound(d.begin(), d.end(), -a[i]) - d.begin();
if (d[l - 1] < -a[i]) {
d[l] = -a[i];
}
l = lower_bound(d.begin(), d.end(), -at[i].second) - d.begin() - 1;
ans = max(ans, at[i].first + l);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
464 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
42 ms |
5460 KB |
Output is correct |
2 |
Correct |
38 ms |
5456 KB |
Output is correct |
3 |
Correct |
37 ms |
5380 KB |
Output is correct |
4 |
Correct |
37 ms |
5456 KB |
Output is correct |
5 |
Correct |
28 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
1624 KB |
Output is correct |
2 |
Correct |
9 ms |
1628 KB |
Output is correct |
3 |
Correct |
10 ms |
1732 KB |
Output is correct |
4 |
Correct |
8 ms |
1492 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
8 ms |
1372 KB |
Output is correct |
7 |
Correct |
9 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
2908 KB |
Output is correct |
2 |
Correct |
18 ms |
2908 KB |
Output is correct |
3 |
Correct |
38 ms |
5468 KB |
Output is correct |
4 |
Correct |
32 ms |
4772 KB |
Output is correct |
5 |
Correct |
15 ms |
2392 KB |
Output is correct |
6 |
Correct |
26 ms |
4448 KB |
Output is correct |
7 |
Correct |
29 ms |
5212 KB |
Output is correct |
8 |
Correct |
14 ms |
2904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 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 |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 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 |
0 ms |
464 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
42 ms |
5460 KB |
Output is correct |
28 |
Correct |
38 ms |
5456 KB |
Output is correct |
29 |
Correct |
37 ms |
5380 KB |
Output is correct |
30 |
Correct |
37 ms |
5456 KB |
Output is correct |
31 |
Correct |
28 ms |
4700 KB |
Output is correct |
32 |
Correct |
9 ms |
1624 KB |
Output is correct |
33 |
Correct |
9 ms |
1628 KB |
Output is correct |
34 |
Correct |
10 ms |
1732 KB |
Output is correct |
35 |
Correct |
8 ms |
1492 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
8 ms |
1372 KB |
Output is correct |
38 |
Correct |
9 ms |
1628 KB |
Output is correct |
39 |
Correct |
19 ms |
2908 KB |
Output is correct |
40 |
Correct |
18 ms |
2908 KB |
Output is correct |
41 |
Correct |
38 ms |
5468 KB |
Output is correct |
42 |
Correct |
32 ms |
4772 KB |
Output is correct |
43 |
Correct |
15 ms |
2392 KB |
Output is correct |
44 |
Correct |
26 ms |
4448 KB |
Output is correct |
45 |
Correct |
29 ms |
5212 KB |
Output is correct |
46 |
Correct |
14 ms |
2904 KB |
Output is correct |
47 |
Correct |
19 ms |
2908 KB |
Output is correct |
48 |
Correct |
19 ms |
2908 KB |
Output is correct |
49 |
Correct |
40 ms |
5468 KB |
Output is correct |
50 |
Correct |
32 ms |
4696 KB |
Output is correct |
51 |
Correct |
23 ms |
3676 KB |
Output is correct |
52 |
Correct |
31 ms |
4704 KB |
Output is correct |
53 |
Correct |
27 ms |
4700 KB |
Output is correct |
54 |
Correct |
28 ms |
5464 KB |
Output is correct |
55 |
Correct |
30 ms |
5468 KB |
Output is correct |