#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int N = 2e5 + 5;
i64 v[N];
int dr[N];
vector<i64> stk;
i64 k;
int ant, n;
int main() {
#ifdef HOME
freopen("glo.in", "r", stdin);
freopen("glo.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i)
cin >> v[i];
if (n == 1) {
cout << "1\n";
return 0; }
for (int i = n; i >= 1; --i) {
auto it = lower_bound(begin(stk), end(stk), -v[i]);
dr[i] = it - begin(stk) + 1;
if (it == end(stk))
stk.push_back(-v[i]);
else
*it = -v[i]; }
stk.clear();
for (int i = 1; i < n; ++i) {
auto it = lower_bound(begin(stk), end(stk), v[i]);
dr[i] = it - begin(stk) + 1;
if (it == end(stk))
stk.push_back(v[i]);
else
*it = v[i];
it = lower_bound(begin(stk), end(stk), v[i + 1] + k);
ant = max(ant, dr[i + 1] + int(it - begin(stk))); }
cout << ant << endl;
return 0; }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
356 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
2704 KB |
Output is correct |
2 |
Correct |
73 ms |
3704 KB |
Output is correct |
3 |
Correct |
60 ms |
3704 KB |
Output is correct |
4 |
Correct |
59 ms |
3832 KB |
Output is correct |
5 |
Correct |
37 ms |
4596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
896 KB |
Output is correct |
2 |
Correct |
15 ms |
1408 KB |
Output is correct |
3 |
Correct |
15 ms |
1356 KB |
Output is correct |
4 |
Correct |
10 ms |
1536 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
15 ms |
1664 KB |
Output is correct |
7 |
Correct |
14 ms |
1504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
1536 KB |
Output is correct |
2 |
Correct |
28 ms |
2432 KB |
Output is correct |
3 |
Correct |
64 ms |
3704 KB |
Output is correct |
4 |
Correct |
36 ms |
4564 KB |
Output is correct |
5 |
Correct |
20 ms |
2560 KB |
Output is correct |
6 |
Correct |
50 ms |
4596 KB |
Output is correct |
7 |
Correct |
38 ms |
4464 KB |
Output is correct |
8 |
Correct |
24 ms |
2560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
3 ms |
356 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
62 ms |
2704 KB |
Output is correct |
28 |
Correct |
73 ms |
3704 KB |
Output is correct |
29 |
Correct |
60 ms |
3704 KB |
Output is correct |
30 |
Correct |
59 ms |
3832 KB |
Output is correct |
31 |
Correct |
37 ms |
4596 KB |
Output is correct |
32 |
Correct |
15 ms |
896 KB |
Output is correct |
33 |
Correct |
15 ms |
1408 KB |
Output is correct |
34 |
Correct |
15 ms |
1356 KB |
Output is correct |
35 |
Correct |
10 ms |
1536 KB |
Output is correct |
36 |
Correct |
2 ms |
384 KB |
Output is correct |
37 |
Correct |
15 ms |
1664 KB |
Output is correct |
38 |
Correct |
14 ms |
1504 KB |
Output is correct |
39 |
Correct |
26 ms |
1536 KB |
Output is correct |
40 |
Correct |
28 ms |
2432 KB |
Output is correct |
41 |
Correct |
64 ms |
3704 KB |
Output is correct |
42 |
Correct |
36 ms |
4564 KB |
Output is correct |
43 |
Correct |
20 ms |
2560 KB |
Output is correct |
44 |
Correct |
50 ms |
4596 KB |
Output is correct |
45 |
Correct |
38 ms |
4464 KB |
Output is correct |
46 |
Correct |
24 ms |
2560 KB |
Output is correct |
47 |
Correct |
29 ms |
2432 KB |
Output is correct |
48 |
Correct |
37 ms |
2484 KB |
Output is correct |
49 |
Correct |
60 ms |
3628 KB |
Output is correct |
50 |
Correct |
33 ms |
4576 KB |
Output is correct |
51 |
Correct |
38 ms |
3828 KB |
Output is correct |
52 |
Correct |
39 ms |
4648 KB |
Output is correct |
53 |
Correct |
36 ms |
4724 KB |
Output is correct |
54 |
Correct |
37 ms |
4592 KB |
Output is correct |
55 |
Correct |
47 ms |
3704 KB |
Output is correct |