#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=2e5+5;
const ll inf=2e18;
int n,x,a[maxN+1],dp[maxN+1];
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>x;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
vector<ll> b(n+1,inf);
b[0]=-inf;
int mx=0;
for(int i=1;i<=n;i++)
{
int k=lower_bound(b.begin(),b.end(),a[i])-b.begin();
b[k]=a[i];
dp[i]=k;
mx=max(mx,k);
}
vector<ll> c(n+1,inf);
c[0]=-inf;
for(int i=n;i>=1;i--)
{
int k=lower_bound(c.begin(),c.end(),x-a[i])-c.begin();
mx=max(mx,dp[i]+k);
k=lower_bound(c.begin(),c.end(),-a[i])-c.begin();
c[k]=-a[i];
}
cout<<mx-1;
}
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
468 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
468 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 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 |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
6944 KB |
Output is correct |
2 |
Correct |
34 ms |
6992 KB |
Output is correct |
3 |
Correct |
36 ms |
7076 KB |
Output is correct |
4 |
Correct |
40 ms |
6936 KB |
Output is correct |
5 |
Correct |
29 ms |
6220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
2136 KB |
Output is correct |
2 |
Correct |
8 ms |
2128 KB |
Output is correct |
3 |
Correct |
8 ms |
2140 KB |
Output is correct |
4 |
Correct |
6 ms |
1864 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1940 KB |
Output is correct |
7 |
Correct |
7 ms |
2140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
3676 KB |
Output is correct |
2 |
Correct |
16 ms |
3672 KB |
Output is correct |
3 |
Correct |
31 ms |
7060 KB |
Output is correct |
4 |
Correct |
26 ms |
6236 KB |
Output is correct |
5 |
Correct |
15 ms |
3164 KB |
Output is correct |
6 |
Correct |
21 ms |
5980 KB |
Output is correct |
7 |
Correct |
24 ms |
6620 KB |
Output is correct |
8 |
Correct |
12 ms |
3704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
0 ms |
348 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 |
468 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 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 |
348 KB |
Output is correct |
27 |
Correct |
40 ms |
6944 KB |
Output is correct |
28 |
Correct |
34 ms |
6992 KB |
Output is correct |
29 |
Correct |
36 ms |
7076 KB |
Output is correct |
30 |
Correct |
40 ms |
6936 KB |
Output is correct |
31 |
Correct |
29 ms |
6220 KB |
Output is correct |
32 |
Correct |
9 ms |
2136 KB |
Output is correct |
33 |
Correct |
8 ms |
2128 KB |
Output is correct |
34 |
Correct |
8 ms |
2140 KB |
Output is correct |
35 |
Correct |
6 ms |
1864 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
1940 KB |
Output is correct |
38 |
Correct |
7 ms |
2140 KB |
Output is correct |
39 |
Correct |
17 ms |
3676 KB |
Output is correct |
40 |
Correct |
16 ms |
3672 KB |
Output is correct |
41 |
Correct |
31 ms |
7060 KB |
Output is correct |
42 |
Correct |
26 ms |
6236 KB |
Output is correct |
43 |
Correct |
15 ms |
3164 KB |
Output is correct |
44 |
Correct |
21 ms |
5980 KB |
Output is correct |
45 |
Correct |
24 ms |
6620 KB |
Output is correct |
46 |
Correct |
12 ms |
3704 KB |
Output is correct |
47 |
Correct |
19 ms |
3672 KB |
Output is correct |
48 |
Correct |
16 ms |
3676 KB |
Output is correct |
49 |
Correct |
33 ms |
7004 KB |
Output is correct |
50 |
Correct |
24 ms |
6232 KB |
Output is correct |
51 |
Correct |
21 ms |
4700 KB |
Output is correct |
52 |
Correct |
25 ms |
6320 KB |
Output is correct |
53 |
Correct |
23 ms |
6164 KB |
Output is correct |
54 |
Correct |
27 ms |
7004 KB |
Output is correct |
55 |
Correct |
29 ms |
7128 KB |
Output is correct |