#include <bits/stdc++.h>
using namespace std;
void solve(int l[], int t[], int n) {
vector<int> v = {t[0]}; l[0] = 1;
for (int i = 1; i < n; ++i) {
if (t[i] > v.back()) {
v.push_back(t[i]);
l[i] = v.size();
}
else {
int x = lower_bound(v.begin(), v.end(), t[i]) - v.begin();
v[x] = t[i];
l[i] = x+1;
}
}
}
int x;
void solvee(int r[], int t[], int n) {
reverse(t, t+n);
for (int i = 0; i < n; ++i) {
t[i] = -t[i];
}
vector<int> v = {t[0]};
r[0] = 1;
for (int i = 1; i < n; ++i) {
int z = lower_bound(v.begin(), v.end(), t[i] + x) - v.begin();
r[i] = z + 1;
if (v.back() < t[i]) {
v.push_back(t[i]);
}
else if (v.back() < t[i]+x) {
int a = lower_bound(v.begin(), v.end(), t[i]) - v.begin();
v[a] = t[i];
}
else {
int y = lower_bound(v.begin(), v.end(), t[i]) - v.begin();
v[y] = t[i];
}
}
reverse(r, r+n);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n >> x;
int t[n];
for (int i = 0; i < n; ++i) {
cin >> t[i];
}
int l[n], r[n];
solve(l, t, n);
solvee(r, t, n);
int ans = l[n-1];
for (int i = 0; i < n; ++i) {
ans = max(ans, l[i] + r[i] - 1);
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
344 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 |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
344 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 |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
344 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 |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
47 ms |
4724 KB |
Output is correct |
2 |
Correct |
44 ms |
4708 KB |
Output is correct |
3 |
Correct |
45 ms |
4696 KB |
Output is correct |
4 |
Correct |
44 ms |
4704 KB |
Output is correct |
5 |
Correct |
19 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1372 KB |
Output is correct |
2 |
Correct |
11 ms |
1532 KB |
Output is correct |
3 |
Correct |
11 ms |
1572 KB |
Output is correct |
4 |
Correct |
6 ms |
1628 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1532 KB |
Output is correct |
7 |
Correct |
8 ms |
1396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2488 KB |
Output is correct |
2 |
Correct |
18 ms |
2592 KB |
Output is correct |
3 |
Correct |
38 ms |
4692 KB |
Output is correct |
4 |
Correct |
21 ms |
4776 KB |
Output is correct |
5 |
Correct |
10 ms |
2584 KB |
Output is correct |
6 |
Correct |
16 ms |
4644 KB |
Output is correct |
7 |
Correct |
20 ms |
5408 KB |
Output is correct |
8 |
Correct |
15 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 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 |
1 ms |
344 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 |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 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 |
344 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 |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
464 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
47 ms |
4724 KB |
Output is correct |
28 |
Correct |
44 ms |
4708 KB |
Output is correct |
29 |
Correct |
45 ms |
4696 KB |
Output is correct |
30 |
Correct |
44 ms |
4704 KB |
Output is correct |
31 |
Correct |
19 ms |
4688 KB |
Output is correct |
32 |
Correct |
10 ms |
1372 KB |
Output is correct |
33 |
Correct |
11 ms |
1532 KB |
Output is correct |
34 |
Correct |
11 ms |
1572 KB |
Output is correct |
35 |
Correct |
6 ms |
1628 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
5 ms |
1532 KB |
Output is correct |
38 |
Correct |
8 ms |
1396 KB |
Output is correct |
39 |
Correct |
18 ms |
2488 KB |
Output is correct |
40 |
Correct |
18 ms |
2592 KB |
Output is correct |
41 |
Correct |
38 ms |
4692 KB |
Output is correct |
42 |
Correct |
21 ms |
4776 KB |
Output is correct |
43 |
Correct |
10 ms |
2584 KB |
Output is correct |
44 |
Correct |
16 ms |
4644 KB |
Output is correct |
45 |
Correct |
20 ms |
5408 KB |
Output is correct |
46 |
Correct |
15 ms |
2396 KB |
Output is correct |
47 |
Correct |
22 ms |
2496 KB |
Output is correct |
48 |
Correct |
22 ms |
2396 KB |
Output is correct |
49 |
Correct |
45 ms |
4700 KB |
Output is correct |
50 |
Correct |
22 ms |
4692 KB |
Output is correct |
51 |
Correct |
18 ms |
3924 KB |
Output is correct |
52 |
Correct |
19 ms |
4864 KB |
Output is correct |
53 |
Correct |
17 ms |
4940 KB |
Output is correct |
54 |
Correct |
23 ms |
5460 KB |
Output is correct |
55 |
Correct |
40 ms |
4680 KB |
Output is correct |