#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define int ll
#define sz size()
#define x first
#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
const ll nmax=5e4+2;
const ll mod = 998244353;
int n, x, s[200001], a[200001];
vector <int> dp;
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
cin>>n>>x;
//dp.pb(0);
for(int i=1; i<=n; i++){
cin>>a[i];
auto it=lower_bound(dp.begin(), dp.end(), a[i]);
if(it==dp.end()){
dp.pb(a[i]);
s[i]=dp.size();
}
else{
dp[it-dp.begin()]=a[i];
s[i]=it-dp.begin()+1;
}
}
// for(int i: dp) cout<<i<<" "; cout<<endl;
//for(int i=1; i<=n; i++) cout<<s[i]<<" ";
int ans=dp.size();
vi lsd;
for(int i=n; i>=1; --i){
auto it=lower_bound(lsd.begin(), lsd.end(), -a[i]);
if(it==lsd.end()) ans=max(ans, s[i]+(int)lsd.size());
else ans=max(ans, s[i]+(it-lsd.begin()));
auto it1=lower_bound(lsd.begin(), lsd.end(), -a[i]-x);
if(it1==lsd.end()) lsd.pb(-a[i]-x);
else lsd[it1-lsd.begin()]=-a[i]-x;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
5380 KB |
Output is correct |
2 |
Correct |
71 ms |
5624 KB |
Output is correct |
3 |
Correct |
71 ms |
5496 KB |
Output is correct |
4 |
Correct |
71 ms |
5460 KB |
Output is correct |
5 |
Correct |
45 ms |
6888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1716 KB |
Output is correct |
2 |
Correct |
18 ms |
1656 KB |
Output is correct |
3 |
Correct |
18 ms |
1580 KB |
Output is correct |
4 |
Correct |
12 ms |
2040 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
13 ms |
2040 KB |
Output is correct |
7 |
Correct |
16 ms |
1656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
2856 KB |
Output is correct |
2 |
Correct |
31 ms |
2948 KB |
Output is correct |
3 |
Correct |
62 ms |
5448 KB |
Output is correct |
4 |
Correct |
47 ms |
6988 KB |
Output is correct |
5 |
Correct |
24 ms |
3700 KB |
Output is correct |
6 |
Correct |
38 ms |
6792 KB |
Output is correct |
7 |
Correct |
48 ms |
7536 KB |
Output is correct |
8 |
Correct |
28 ms |
2936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
2 ms |
376 KB |
Output is correct |
25 |
Correct |
2 ms |
376 KB |
Output is correct |
26 |
Correct |
2 ms |
376 KB |
Output is correct |
27 |
Correct |
71 ms |
5380 KB |
Output is correct |
28 |
Correct |
71 ms |
5624 KB |
Output is correct |
29 |
Correct |
71 ms |
5496 KB |
Output is correct |
30 |
Correct |
71 ms |
5460 KB |
Output is correct |
31 |
Correct |
45 ms |
6888 KB |
Output is correct |
32 |
Correct |
18 ms |
1716 KB |
Output is correct |
33 |
Correct |
18 ms |
1656 KB |
Output is correct |
34 |
Correct |
18 ms |
1580 KB |
Output is correct |
35 |
Correct |
12 ms |
2040 KB |
Output is correct |
36 |
Correct |
2 ms |
376 KB |
Output is correct |
37 |
Correct |
13 ms |
2040 KB |
Output is correct |
38 |
Correct |
16 ms |
1656 KB |
Output is correct |
39 |
Correct |
32 ms |
2856 KB |
Output is correct |
40 |
Correct |
31 ms |
2948 KB |
Output is correct |
41 |
Correct |
62 ms |
5448 KB |
Output is correct |
42 |
Correct |
47 ms |
6988 KB |
Output is correct |
43 |
Correct |
24 ms |
3700 KB |
Output is correct |
44 |
Correct |
38 ms |
6792 KB |
Output is correct |
45 |
Correct |
48 ms |
7536 KB |
Output is correct |
46 |
Correct |
28 ms |
2936 KB |
Output is correct |
47 |
Correct |
35 ms |
2940 KB |
Output is correct |
48 |
Correct |
35 ms |
2908 KB |
Output is correct |
49 |
Correct |
71 ms |
5456 KB |
Output is correct |
50 |
Correct |
45 ms |
6896 KB |
Output is correct |
51 |
Correct |
40 ms |
5868 KB |
Output is correct |
52 |
Correct |
50 ms |
7032 KB |
Output is correct |
53 |
Correct |
40 ms |
7020 KB |
Output is correct |
54 |
Correct |
49 ms |
7792 KB |
Output is correct |
55 |
Correct |
59 ms |
5368 KB |
Output is correct |