#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define F first
#define S second
#define coy cout<<"YES\n"
#define con cout<<"NO\n"
#define co1 cout<<"-1\n"
#define sc(x) scanf("%lld",&x)
#define all(x) x.begin(),x.end()
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int SI=3e5+7;
ll INF=8e18+7;
int dx[] = {1 , -1 , 0 , 0};
int dy[] = {0 , 0 , 1 , -1};
int MOD=1e9+7;
ll n,x,a[SI],pr[SI];
int main()
{
fast
cin>>n>>x;
for (int i=0;i<n;i++)
cin>>a[i];
vector <ll> dp(n,INF);
for (int i=0;i<n;i++)
{
ll j=lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
dp[j]=a[i];
pr[i]=j+1;
}
ll ans=0;
vector <ll> dp2(n,INF);
for (int i=n-1;i>=0;i--)
{
ll j=lower_bound(dp2.begin(),dp2.end(),-a[i]+x)-dp2.begin();
ans=max(ans,pr[i]+j);
j=lower_bound(dp2.begin(),dp2.end(),-a[i])-dp2.begin();
dp2[j]=-a[i];
}
cout <<ans<<"\n";
// use scanf not cin
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
8544 KB |
Output is correct |
2 |
Correct |
54 ms |
8440 KB |
Output is correct |
3 |
Correct |
53 ms |
8436 KB |
Output is correct |
4 |
Correct |
51 ms |
8388 KB |
Output is correct |
5 |
Correct |
36 ms |
7608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
2360 KB |
Output is correct |
2 |
Correct |
13 ms |
2380 KB |
Output is correct |
3 |
Correct |
12 ms |
2308 KB |
Output is correct |
4 |
Correct |
12 ms |
2124 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
9 ms |
2168 KB |
Output is correct |
7 |
Correct |
10 ms |
2376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
4352 KB |
Output is correct |
2 |
Correct |
25 ms |
4292 KB |
Output is correct |
3 |
Correct |
48 ms |
8416 KB |
Output is correct |
4 |
Correct |
39 ms |
7620 KB |
Output is correct |
5 |
Correct |
22 ms |
3916 KB |
Output is correct |
6 |
Correct |
31 ms |
7340 KB |
Output is correct |
7 |
Correct |
37 ms |
8056 KB |
Output is correct |
8 |
Correct |
20 ms |
4428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
52 ms |
8544 KB |
Output is correct |
28 |
Correct |
54 ms |
8440 KB |
Output is correct |
29 |
Correct |
53 ms |
8436 KB |
Output is correct |
30 |
Correct |
51 ms |
8388 KB |
Output is correct |
31 |
Correct |
36 ms |
7608 KB |
Output is correct |
32 |
Correct |
13 ms |
2360 KB |
Output is correct |
33 |
Correct |
13 ms |
2380 KB |
Output is correct |
34 |
Correct |
12 ms |
2308 KB |
Output is correct |
35 |
Correct |
12 ms |
2124 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
9 ms |
2168 KB |
Output is correct |
38 |
Correct |
10 ms |
2376 KB |
Output is correct |
39 |
Correct |
23 ms |
4352 KB |
Output is correct |
40 |
Correct |
25 ms |
4292 KB |
Output is correct |
41 |
Correct |
48 ms |
8416 KB |
Output is correct |
42 |
Correct |
39 ms |
7620 KB |
Output is correct |
43 |
Correct |
22 ms |
3916 KB |
Output is correct |
44 |
Correct |
31 ms |
7340 KB |
Output is correct |
45 |
Correct |
37 ms |
8056 KB |
Output is correct |
46 |
Correct |
20 ms |
4428 KB |
Output is correct |
47 |
Correct |
26 ms |
4292 KB |
Output is correct |
48 |
Correct |
26 ms |
4300 KB |
Output is correct |
49 |
Correct |
51 ms |
8480 KB |
Output is correct |
50 |
Correct |
37 ms |
7620 KB |
Output is correct |
51 |
Correct |
31 ms |
5840 KB |
Output is correct |
52 |
Correct |
38 ms |
7780 KB |
Output is correct |
53 |
Correct |
31 ms |
7736 KB |
Output is correct |
54 |
Correct |
38 ms |
8476 KB |
Output is correct |
55 |
Correct |
44 ms |
8528 KB |
Output is correct |