#include <bits/stdc++.h>
using namespace std;
const long long MAX=2*1e5+10;
long long pr[MAX];
long long niza[MAX];
int main()
{
long long n,x;
cin>>n>>x;
for(long long i=0; i<n; i++)cin>>niza[i];
vector<long long> help(n);
for(long long i=0; i<n; i++)help[i]=INT_MAX;
long long res=0;
for(long long i=0; i<n; i++)
{
long long nw=lower_bound(help.begin(),help.end(),niza[i])-help.begin();
help[nw]=niza[i];
pr[i]=nw+1;
res=max(res,pr[i]);
}
for(long long i=0; i<n; i++)help[i]=INT_MAX;
for (long long i=n-1; i>=0; i--) {
long long nw=lower_bound(help.begin(),help.end(),-niza[i]+x)-help.begin();
res=max(res,pr[i]+nw);
long long tmp=lower_bound(help.begin(),help.end(),-niza[i])-help.begin();
help[tmp]=-niza[i];
}
cout<<res<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
75 ms |
6996 KB |
Output is correct |
2 |
Correct |
75 ms |
6992 KB |
Output is correct |
3 |
Correct |
74 ms |
7004 KB |
Output is correct |
4 |
Correct |
77 ms |
6992 KB |
Output is correct |
5 |
Correct |
49 ms |
6224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1880 KB |
Output is correct |
2 |
Correct |
18 ms |
1884 KB |
Output is correct |
3 |
Correct |
19 ms |
1884 KB |
Output is correct |
4 |
Correct |
13 ms |
1884 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
13 ms |
1880 KB |
Output is correct |
7 |
Correct |
16 ms |
1956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
3672 KB |
Output is correct |
2 |
Correct |
36 ms |
3664 KB |
Output is correct |
3 |
Correct |
78 ms |
6996 KB |
Output is correct |
4 |
Correct |
57 ms |
6276 KB |
Output is correct |
5 |
Correct |
26 ms |
3164 KB |
Output is correct |
6 |
Correct |
48 ms |
5976 KB |
Output is correct |
7 |
Correct |
64 ms |
6736 KB |
Output is correct |
8 |
Correct |
35 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 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 |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
444 KB |
Output is correct |
19 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
444 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
75 ms |
6996 KB |
Output is correct |
28 |
Correct |
75 ms |
6992 KB |
Output is correct |
29 |
Correct |
74 ms |
7004 KB |
Output is correct |
30 |
Correct |
77 ms |
6992 KB |
Output is correct |
31 |
Correct |
49 ms |
6224 KB |
Output is correct |
32 |
Correct |
19 ms |
1880 KB |
Output is correct |
33 |
Correct |
18 ms |
1884 KB |
Output is correct |
34 |
Correct |
19 ms |
1884 KB |
Output is correct |
35 |
Correct |
13 ms |
1884 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
13 ms |
1880 KB |
Output is correct |
38 |
Correct |
16 ms |
1956 KB |
Output is correct |
39 |
Correct |
35 ms |
3672 KB |
Output is correct |
40 |
Correct |
36 ms |
3664 KB |
Output is correct |
41 |
Correct |
78 ms |
6996 KB |
Output is correct |
42 |
Correct |
57 ms |
6276 KB |
Output is correct |
43 |
Correct |
26 ms |
3164 KB |
Output is correct |
44 |
Correct |
48 ms |
5976 KB |
Output is correct |
45 |
Correct |
64 ms |
6736 KB |
Output is correct |
46 |
Correct |
35 ms |
3676 KB |
Output is correct |
47 |
Correct |
40 ms |
3664 KB |
Output is correct |
48 |
Correct |
40 ms |
3688 KB |
Output is correct |
49 |
Correct |
87 ms |
6992 KB |
Output is correct |
50 |
Correct |
49 ms |
6196 KB |
Output is correct |
51 |
Correct |
48 ms |
4688 KB |
Output is correct |
52 |
Correct |
53 ms |
6372 KB |
Output is correct |
53 |
Correct |
48 ms |
6224 KB |
Output is correct |
54 |
Correct |
68 ms |
6996 KB |
Output is correct |
55 |
Correct |
74 ms |
7052 KB |
Output is correct |