#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,x;
int a[N],dp[N];
vector<int> v1,v2;
int ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> x;
for(int i=1;i<=n;i++)cin >> a[i];
for(int i=1;i<=n;i++){
auto it=lower_bound(v1.begin(),v1.end(),a[i]);
dp[i]=it-v1.begin()+1;
if(it==v1.end())v1.emplace_back(a[i]);
else *it=a[i];
}
for(int i=n;i>=1;i--){
auto it=lower_bound(v2.begin(),v2.end(),-a[i]);
ans=max(ans,dp[i]+int(it-v2.begin()));
a[i]+=x;
it=lower_bound(v2.begin(),v2.end(),-a[i]);
if(it==v2.end())v2.emplace_back(-a[i]);
else *it=-a[i];
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
856 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
856 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
444 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
3164 KB |
Output is correct |
2 |
Correct |
52 ms |
3160 KB |
Output is correct |
3 |
Correct |
50 ms |
3088 KB |
Output is correct |
4 |
Correct |
46 ms |
3156 KB |
Output is correct |
5 |
Correct |
22 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1116 KB |
Output is correct |
2 |
Correct |
11 ms |
1188 KB |
Output is correct |
3 |
Correct |
11 ms |
1116 KB |
Output is correct |
4 |
Correct |
7 ms |
1372 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
5 ms |
1372 KB |
Output is correct |
7 |
Correct |
10 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1876 KB |
Output is correct |
2 |
Correct |
19 ms |
1920 KB |
Output is correct |
3 |
Correct |
38 ms |
3156 KB |
Output is correct |
4 |
Correct |
22 ms |
3792 KB |
Output is correct |
5 |
Correct |
11 ms |
2272 KB |
Output is correct |
6 |
Correct |
20 ms |
3796 KB |
Output is correct |
7 |
Correct |
25 ms |
4304 KB |
Output is correct |
8 |
Correct |
16 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
856 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
444 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
47 ms |
3164 KB |
Output is correct |
28 |
Correct |
52 ms |
3160 KB |
Output is correct |
29 |
Correct |
50 ms |
3088 KB |
Output is correct |
30 |
Correct |
46 ms |
3156 KB |
Output is correct |
31 |
Correct |
22 ms |
3796 KB |
Output is correct |
32 |
Correct |
11 ms |
1116 KB |
Output is correct |
33 |
Correct |
11 ms |
1188 KB |
Output is correct |
34 |
Correct |
11 ms |
1116 KB |
Output is correct |
35 |
Correct |
7 ms |
1372 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
5 ms |
1372 KB |
Output is correct |
38 |
Correct |
10 ms |
1236 KB |
Output is correct |
39 |
Correct |
19 ms |
1876 KB |
Output is correct |
40 |
Correct |
19 ms |
1920 KB |
Output is correct |
41 |
Correct |
38 ms |
3156 KB |
Output is correct |
42 |
Correct |
22 ms |
3792 KB |
Output is correct |
43 |
Correct |
11 ms |
2272 KB |
Output is correct |
44 |
Correct |
20 ms |
3796 KB |
Output is correct |
45 |
Correct |
25 ms |
4304 KB |
Output is correct |
46 |
Correct |
16 ms |
1884 KB |
Output is correct |
47 |
Correct |
22 ms |
1880 KB |
Output is correct |
48 |
Correct |
22 ms |
2032 KB |
Output is correct |
49 |
Correct |
48 ms |
3288 KB |
Output is correct |
50 |
Correct |
22 ms |
3804 KB |
Output is correct |
51 |
Correct |
21 ms |
3404 KB |
Output is correct |
52 |
Correct |
23 ms |
3744 KB |
Output is correct |
53 |
Correct |
23 ms |
3864 KB |
Output is correct |
54 |
Correct |
24 ms |
4308 KB |
Output is correct |
55 |
Correct |
36 ms |
3196 KB |
Output is correct |