#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
using namespace std;
signed main() {
ios_base::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> pref(n,0);
vector<int> suff(n,0);
vector<int> lis;
lis.push_back(t[0]);
pref[0]=1;
for (int i = 1; i < n; i++)
{
if(t[i]+x>lis.back()) pref[i]=sz(lis)+1;
else{
int p=(lower_bound(lis.begin(), lis.end(), t[i]+x))-lis.begin();
pref[i]=p+1;
}
if(t[i]>lis.back()) {
lis.push_back(t[i]);
}else{
int p=(lower_bound(lis.begin(), lis.end(), t[i]))-lis.begin();
lis[p]=t[i];
}
}
lis.clear();
lis.push_back(-t[n-1]);
suff[n-1]=1;
for (int i = n-2; i >= 0; i--)
{
if(-t[i]>lis.back()) {
lis.push_back(-t[i]);
suff[i]=sz(lis);
}else{
int p=(lower_bound(lis.begin(), lis.end(), -t[i]))-lis.begin();
lis[p]=-t[i];
suff[i]=p+1;
}
}
int mx=max(pref[n-1],suff[0]);
for (int i = 1; i < n; i++) mx=max(mx,pref[i]+suff[i]-1);
cout << mx << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
456 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 |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
5108 KB |
Output is correct |
2 |
Correct |
44 ms |
7032 KB |
Output is correct |
3 |
Correct |
45 ms |
6996 KB |
Output is correct |
4 |
Correct |
45 ms |
6992 KB |
Output is correct |
5 |
Correct |
18 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1632 KB |
Output is correct |
2 |
Correct |
11 ms |
1884 KB |
Output is correct |
3 |
Correct |
11 ms |
2140 KB |
Output is correct |
4 |
Correct |
5 ms |
2144 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
4 ms |
2252 KB |
Output is correct |
7 |
Correct |
9 ms |
2152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
2900 KB |
Output is correct |
2 |
Correct |
18 ms |
3664 KB |
Output is correct |
3 |
Correct |
38 ms |
6992 KB |
Output is correct |
4 |
Correct |
17 ms |
7388 KB |
Output is correct |
5 |
Correct |
8 ms |
3808 KB |
Output is correct |
6 |
Correct |
15 ms |
7132 KB |
Output is correct |
7 |
Correct |
18 ms |
7900 KB |
Output is correct |
8 |
Correct |
15 ms |
3800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 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 |
456 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 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 |
456 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 |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 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 |
348 KB |
Output is correct |
27 |
Correct |
44 ms |
5108 KB |
Output is correct |
28 |
Correct |
44 ms |
7032 KB |
Output is correct |
29 |
Correct |
45 ms |
6996 KB |
Output is correct |
30 |
Correct |
45 ms |
6992 KB |
Output is correct |
31 |
Correct |
18 ms |
7380 KB |
Output is correct |
32 |
Correct |
10 ms |
1632 KB |
Output is correct |
33 |
Correct |
11 ms |
1884 KB |
Output is correct |
34 |
Correct |
11 ms |
2140 KB |
Output is correct |
35 |
Correct |
5 ms |
2144 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
4 ms |
2252 KB |
Output is correct |
38 |
Correct |
9 ms |
2152 KB |
Output is correct |
39 |
Correct |
18 ms |
2900 KB |
Output is correct |
40 |
Correct |
18 ms |
3664 KB |
Output is correct |
41 |
Correct |
38 ms |
6992 KB |
Output is correct |
42 |
Correct |
17 ms |
7388 KB |
Output is correct |
43 |
Correct |
8 ms |
3808 KB |
Output is correct |
44 |
Correct |
15 ms |
7132 KB |
Output is correct |
45 |
Correct |
18 ms |
7900 KB |
Output is correct |
46 |
Correct |
15 ms |
3800 KB |
Output is correct |
47 |
Correct |
22 ms |
3796 KB |
Output is correct |
48 |
Correct |
22 ms |
4056 KB |
Output is correct |
49 |
Correct |
45 ms |
7004 KB |
Output is correct |
50 |
Correct |
22 ms |
7388 KB |
Output is correct |
51 |
Correct |
15 ms |
5848 KB |
Output is correct |
52 |
Correct |
17 ms |
7388 KB |
Output is correct |
53 |
Correct |
16 ms |
7520 KB |
Output is correct |
54 |
Correct |
18 ms |
8152 KB |
Output is correct |
55 |
Correct |
35 ms |
7004 KB |
Output is correct |