#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 3e10;
int main() {
ll n,x;
cin >>n >> x;
vector<ll> v(n);
for(ll&i : v) cin >> i;
vector<ll> suf(n+1, 0), lds(n+1, -1);
lds[0] = INF;
for(ll i = n-1; i >= 0; i--) {
ll l = 0, r = n, mo = n;
while(l <= r) {
ll mid = (l + r) / 2;
if(lds[mid] > v[i]) {
l = mid+1;
mo = mid;
}
else r = mid-1;
}
//cout << i << ": " << mo << endl;
mo++;
suf[i] = mo;
lds[mo] = v[i];
}
/*for(ll i = 0; i < n; i++) cout << suf[i] << ' ';
cout << endl;*/
vector<ll> dp(n+1, INF);
dp[0] = -1;
ll mo = 0;
for(ll i = 0; i < n; i++) {
ll a = lower_bound(dp.begin(), dp.end(), v[i] + x) - dp.begin();
/*cout << i << ": ";
for(ll i = 0; i <= n; i++) cout << dp[i] << ' ';
cout << endl << a << ", " << suf[i] << endl;*/
mo = max(mo, a-1 + suf[i]);
ll j = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
dp[j] = v[i];
}
cout << mo << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
244 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
6556 KB |
Output is correct |
2 |
Correct |
102 ms |
6468 KB |
Output is correct |
3 |
Correct |
103 ms |
6456 KB |
Output is correct |
4 |
Correct |
105 ms |
6556 KB |
Output is correct |
5 |
Correct |
71 ms |
6468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1876 KB |
Output is correct |
2 |
Correct |
25 ms |
1852 KB |
Output is correct |
3 |
Correct |
26 ms |
1844 KB |
Output is correct |
4 |
Correct |
19 ms |
1876 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
1876 KB |
Output is correct |
7 |
Correct |
24 ms |
1844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
3384 KB |
Output is correct |
2 |
Correct |
50 ms |
4392 KB |
Output is correct |
3 |
Correct |
102 ms |
7856 KB |
Output is correct |
4 |
Correct |
75 ms |
7612 KB |
Output is correct |
5 |
Correct |
37 ms |
4008 KB |
Output is correct |
6 |
Correct |
69 ms |
7468 KB |
Output is correct |
7 |
Correct |
89 ms |
7652 KB |
Output is correct |
8 |
Correct |
49 ms |
4408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
244 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
104 ms |
6556 KB |
Output is correct |
28 |
Correct |
102 ms |
6468 KB |
Output is correct |
29 |
Correct |
103 ms |
6456 KB |
Output is correct |
30 |
Correct |
105 ms |
6556 KB |
Output is correct |
31 |
Correct |
71 ms |
6468 KB |
Output is correct |
32 |
Correct |
25 ms |
1876 KB |
Output is correct |
33 |
Correct |
25 ms |
1852 KB |
Output is correct |
34 |
Correct |
26 ms |
1844 KB |
Output is correct |
35 |
Correct |
19 ms |
1876 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
18 ms |
1876 KB |
Output is correct |
38 |
Correct |
24 ms |
1844 KB |
Output is correct |
39 |
Correct |
50 ms |
3384 KB |
Output is correct |
40 |
Correct |
50 ms |
4392 KB |
Output is correct |
41 |
Correct |
102 ms |
7856 KB |
Output is correct |
42 |
Correct |
75 ms |
7612 KB |
Output is correct |
43 |
Correct |
37 ms |
4008 KB |
Output is correct |
44 |
Correct |
69 ms |
7468 KB |
Output is correct |
45 |
Correct |
89 ms |
7652 KB |
Output is correct |
46 |
Correct |
49 ms |
4408 KB |
Output is correct |
47 |
Correct |
53 ms |
4300 KB |
Output is correct |
48 |
Correct |
51 ms |
4400 KB |
Output is correct |
49 |
Correct |
103 ms |
7976 KB |
Output is correct |
50 |
Correct |
72 ms |
7684 KB |
Output is correct |
51 |
Correct |
62 ms |
5776 KB |
Output is correct |
52 |
Correct |
83 ms |
7884 KB |
Output is correct |
53 |
Correct |
73 ms |
7732 KB |
Output is correct |
54 |
Correct |
93 ms |
7936 KB |
Output is correct |
55 |
Correct |
96 ms |
7968 KB |
Output is correct |