#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5, inf = 2e9+1;
int a[N], best[N];
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,d;
cin >> n >> d;
for (int i=0; i<n; ++i){
cin >> a[i];
}
vector<int> dp(N,inf);
for (int i=0; i<n; ++i){
best[i] = lower_bound(dp.begin(),dp.end(),a[i]+d)-dp.begin()+1;
int pos = lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
dp[pos] = a[i];
}
dp = vector<int>(N,inf);
int ans = 0;
for (int i=n-1; i>=0; --i){
int lds = lower_bound(dp.begin(),dp.end(),-a[i]-d)-dp.begin();
ans = max(ans,best[i]+lds);
dp[lds] = -a[i]-d;
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3400 KB |
Output is correct |
4 |
Correct |
2 ms |
3396 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3400 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3400 KB |
Output is correct |
4 |
Correct |
2 ms |
3396 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3400 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3400 KB |
Output is correct |
4 |
Correct |
2 ms |
3396 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3400 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
8492 KB |
Output is correct |
2 |
Correct |
56 ms |
8456 KB |
Output is correct |
3 |
Correct |
52 ms |
8412 KB |
Output is correct |
4 |
Correct |
53 ms |
8472 KB |
Output is correct |
5 |
Correct |
41 ms |
7688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
4696 KB |
Output is correct |
2 |
Correct |
14 ms |
4676 KB |
Output is correct |
3 |
Correct |
14 ms |
4692 KB |
Output is correct |
4 |
Correct |
11 ms |
4472 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
11 ms |
4436 KB |
Output is correct |
7 |
Correct |
12 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
5944 KB |
Output is correct |
2 |
Correct |
24 ms |
5960 KB |
Output is correct |
3 |
Correct |
63 ms |
8420 KB |
Output is correct |
4 |
Correct |
42 ms |
7620 KB |
Output is correct |
5 |
Correct |
21 ms |
5588 KB |
Output is correct |
6 |
Correct |
35 ms |
7504 KB |
Output is correct |
7 |
Correct |
39 ms |
8252 KB |
Output is correct |
8 |
Correct |
31 ms |
5956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3412 KB |
Output is correct |
2 |
Correct |
2 ms |
3412 KB |
Output is correct |
3 |
Correct |
2 ms |
3400 KB |
Output is correct |
4 |
Correct |
2 ms |
3396 KB |
Output is correct |
5 |
Correct |
2 ms |
3412 KB |
Output is correct |
6 |
Correct |
2 ms |
3412 KB |
Output is correct |
7 |
Correct |
2 ms |
3400 KB |
Output is correct |
8 |
Correct |
2 ms |
3412 KB |
Output is correct |
9 |
Correct |
2 ms |
3412 KB |
Output is correct |
10 |
Correct |
2 ms |
3412 KB |
Output is correct |
11 |
Correct |
2 ms |
3412 KB |
Output is correct |
12 |
Correct |
2 ms |
3412 KB |
Output is correct |
13 |
Correct |
2 ms |
3412 KB |
Output is correct |
14 |
Correct |
2 ms |
3412 KB |
Output is correct |
15 |
Correct |
2 ms |
3412 KB |
Output is correct |
16 |
Correct |
2 ms |
3412 KB |
Output is correct |
17 |
Correct |
2 ms |
3412 KB |
Output is correct |
18 |
Correct |
2 ms |
3404 KB |
Output is correct |
19 |
Correct |
2 ms |
3412 KB |
Output is correct |
20 |
Correct |
2 ms |
3412 KB |
Output is correct |
21 |
Correct |
2 ms |
3412 KB |
Output is correct |
22 |
Correct |
2 ms |
3412 KB |
Output is correct |
23 |
Correct |
2 ms |
3412 KB |
Output is correct |
24 |
Correct |
2 ms |
3412 KB |
Output is correct |
25 |
Correct |
2 ms |
3412 KB |
Output is correct |
26 |
Correct |
2 ms |
3412 KB |
Output is correct |
27 |
Correct |
61 ms |
8492 KB |
Output is correct |
28 |
Correct |
56 ms |
8456 KB |
Output is correct |
29 |
Correct |
52 ms |
8412 KB |
Output is correct |
30 |
Correct |
53 ms |
8472 KB |
Output is correct |
31 |
Correct |
41 ms |
7688 KB |
Output is correct |
32 |
Correct |
14 ms |
4696 KB |
Output is correct |
33 |
Correct |
14 ms |
4676 KB |
Output is correct |
34 |
Correct |
14 ms |
4692 KB |
Output is correct |
35 |
Correct |
11 ms |
4472 KB |
Output is correct |
36 |
Correct |
2 ms |
3412 KB |
Output is correct |
37 |
Correct |
11 ms |
4436 KB |
Output is correct |
38 |
Correct |
12 ms |
4728 KB |
Output is correct |
39 |
Correct |
28 ms |
5944 KB |
Output is correct |
40 |
Correct |
24 ms |
5960 KB |
Output is correct |
41 |
Correct |
63 ms |
8420 KB |
Output is correct |
42 |
Correct |
42 ms |
7620 KB |
Output is correct |
43 |
Correct |
21 ms |
5588 KB |
Output is correct |
44 |
Correct |
35 ms |
7504 KB |
Output is correct |
45 |
Correct |
39 ms |
8252 KB |
Output is correct |
46 |
Correct |
31 ms |
5956 KB |
Output is correct |
47 |
Correct |
31 ms |
5940 KB |
Output is correct |
48 |
Correct |
28 ms |
5964 KB |
Output is correct |
49 |
Correct |
55 ms |
8624 KB |
Output is correct |
50 |
Correct |
41 ms |
7724 KB |
Output is correct |
51 |
Correct |
37 ms |
6624 KB |
Output is correct |
52 |
Correct |
44 ms |
7804 KB |
Output is correct |
53 |
Correct |
35 ms |
7756 KB |
Output is correct |
54 |
Correct |
41 ms |
8444 KB |
Output is correct |
55 |
Correct |
47 ms |
8428 KB |
Output is correct |