#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define p push
#define pii pair<int,int>
#define ppii pair<int,pii>
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define set(x) memset(x,-1,sizeof(x));
#define int long long
const int mxn=1e9;
int n,x;
int32_t main(){
fastio
cin>>n>>x;
vector<int>v(n);
for(int i=0;i<n;i++)cin>>v[i];
vector<int>lis,dp(n);
for(int i=0;i<n;i++){
int k;
if(lis.empty()||lis.back()<v[i])lis.pb(v[i]),k=lis.size();
else{
auto it=lower_bound(lis.begin(),lis.end(),v[i]);
(*it)=v[i];
k=it-lis.begin()+1;
}
dp[i]=k;
}
vector<int>lis2;
int ans=0;
for(int i=n-1;i>=0;i--){
int k;
if(lis2.empty()||lis2.back()>v[i])k=lis2.size()+1;
else{
auto it=upper_bound(lis2.rbegin(),lis2.rend(),v[i]);
k=lis2.rend()-it+1;
}
ans=max(ans,dp[i]+k-1);
if(lis2.empty()||lis2.back()>v[i]+x)lis2.pb(v[i]+x);
else{
auto it=upper_bound(lis2.rbegin(),lis2.rend(),v[i]+x);
it--;
(*it)=v[i]+x;
}
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
3460 KB |
Output is correct |
2 |
Correct |
48 ms |
3412 KB |
Output is correct |
3 |
Correct |
47 ms |
3412 KB |
Output is correct |
4 |
Correct |
48 ms |
3412 KB |
Output is correct |
5 |
Correct |
19 ms |
5728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1108 KB |
Output is correct |
2 |
Correct |
12 ms |
1132 KB |
Output is correct |
3 |
Correct |
14 ms |
1120 KB |
Output is correct |
4 |
Correct |
5 ms |
1624 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
6 ms |
1872 KB |
Output is correct |
7 |
Correct |
9 ms |
1608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1876 KB |
Output is correct |
2 |
Correct |
19 ms |
1920 KB |
Output is correct |
3 |
Correct |
37 ms |
3436 KB |
Output is correct |
4 |
Correct |
18 ms |
5780 KB |
Output is correct |
5 |
Correct |
9 ms |
3028 KB |
Output is correct |
6 |
Correct |
21 ms |
5584 KB |
Output is correct |
7 |
Correct |
19 ms |
5584 KB |
Output is correct |
8 |
Correct |
15 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
328 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
48 ms |
3460 KB |
Output is correct |
28 |
Correct |
48 ms |
3412 KB |
Output is correct |
29 |
Correct |
47 ms |
3412 KB |
Output is correct |
30 |
Correct |
48 ms |
3412 KB |
Output is correct |
31 |
Correct |
19 ms |
5728 KB |
Output is correct |
32 |
Correct |
11 ms |
1108 KB |
Output is correct |
33 |
Correct |
12 ms |
1132 KB |
Output is correct |
34 |
Correct |
14 ms |
1120 KB |
Output is correct |
35 |
Correct |
5 ms |
1624 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
6 ms |
1872 KB |
Output is correct |
38 |
Correct |
9 ms |
1608 KB |
Output is correct |
39 |
Correct |
18 ms |
1876 KB |
Output is correct |
40 |
Correct |
19 ms |
1920 KB |
Output is correct |
41 |
Correct |
37 ms |
3436 KB |
Output is correct |
42 |
Correct |
18 ms |
5780 KB |
Output is correct |
43 |
Correct |
9 ms |
3028 KB |
Output is correct |
44 |
Correct |
21 ms |
5584 KB |
Output is correct |
45 |
Correct |
19 ms |
5584 KB |
Output is correct |
46 |
Correct |
15 ms |
1876 KB |
Output is correct |
47 |
Correct |
23 ms |
2872 KB |
Output is correct |
48 |
Correct |
23 ms |
2880 KB |
Output is correct |
49 |
Correct |
48 ms |
5312 KB |
Output is correct |
50 |
Correct |
23 ms |
6912 KB |
Output is correct |
51 |
Correct |
16 ms |
5840 KB |
Output is correct |
52 |
Correct |
18 ms |
6996 KB |
Output is correct |
53 |
Correct |
17 ms |
7000 KB |
Output is correct |
54 |
Correct |
21 ms |
7632 KB |
Output is correct |
55 |
Correct |
37 ms |
5416 KB |
Output is correct |