#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, x;
vector<int> t;
int bs(int val, vector<int> &LIS) {
int l=0, r=LIS.size()-1;
int ans=-1;
while (l<=r) {
int mid=l+(r-l)/2;
if (LIS[mid]>val) {
l=mid+1;
ans=mid+1;
} else {
r=mid-1;
}
}
return ans;
}
void solve() {
cin >> n >> x;
t.resize(n);
for (auto &u: t) cin >> u;
vector<int> corr(n, 0);
vector<int> LIS;
for (int i=n-1; i>=0; i--) {
corr[i]=max(0LL, bs(t[i]-x, LIS));
int lb=bs(t[i], LIS);
if (lb>=(int)LIS.size() || i==n-1) {
LIS.push_back(t[i]);
} else if (lb==-1) {
LIS[0]=t[i];
} else {
LIS[lb]=t[i];
}
}
int ans=1;
LIS.clear();
for (int i=0; i<n; i++) {
auto lb=lower_bound(LIS.begin(), LIS.end(), t[i]);
if (lb==LIS.end()) {
LIS.push_back(t[i]);
ans=max(ans, (int)LIS.size()+corr[i]);
} else {
LIS[lb-LIS.begin()]=t[i];
ans=max(ans, (int)(lb-LIS.begin()+1)+corr[i]);
}
}
cout << ans << endl;
return;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
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 |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 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 |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
5336 KB |
Output is correct |
2 |
Correct |
45 ms |
5468 KB |
Output is correct |
3 |
Correct |
46 ms |
5532 KB |
Output is correct |
4 |
Correct |
46 ms |
5524 KB |
Output is correct |
5 |
Correct |
25 ms |
5860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
1628 KB |
Output is correct |
2 |
Correct |
12 ms |
1628 KB |
Output is correct |
3 |
Correct |
11 ms |
1628 KB |
Output is correct |
4 |
Correct |
6 ms |
1868 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
6 ms |
1912 KB |
Output is correct |
7 |
Correct |
9 ms |
1752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2772 KB |
Output is correct |
2 |
Correct |
19 ms |
2908 KB |
Output is correct |
3 |
Correct |
39 ms |
5468 KB |
Output is correct |
4 |
Correct |
23 ms |
5844 KB |
Output is correct |
5 |
Correct |
12 ms |
3040 KB |
Output is correct |
6 |
Correct |
21 ms |
5588 KB |
Output is correct |
7 |
Correct |
25 ms |
6276 KB |
Output is correct |
8 |
Correct |
16 ms |
2908 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 |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
45 ms |
5336 KB |
Output is correct |
28 |
Correct |
45 ms |
5468 KB |
Output is correct |
29 |
Correct |
46 ms |
5532 KB |
Output is correct |
30 |
Correct |
46 ms |
5524 KB |
Output is correct |
31 |
Correct |
25 ms |
5860 KB |
Output is correct |
32 |
Correct |
11 ms |
1628 KB |
Output is correct |
33 |
Correct |
12 ms |
1628 KB |
Output is correct |
34 |
Correct |
11 ms |
1628 KB |
Output is correct |
35 |
Correct |
6 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
6 ms |
1912 KB |
Output is correct |
38 |
Correct |
9 ms |
1752 KB |
Output is correct |
39 |
Correct |
19 ms |
2772 KB |
Output is correct |
40 |
Correct |
19 ms |
2908 KB |
Output is correct |
41 |
Correct |
39 ms |
5468 KB |
Output is correct |
42 |
Correct |
23 ms |
5844 KB |
Output is correct |
43 |
Correct |
12 ms |
3040 KB |
Output is correct |
44 |
Correct |
21 ms |
5588 KB |
Output is correct |
45 |
Correct |
25 ms |
6276 KB |
Output is correct |
46 |
Correct |
16 ms |
2908 KB |
Output is correct |
47 |
Correct |
22 ms |
3024 KB |
Output is correct |
48 |
Correct |
23 ms |
3032 KB |
Output is correct |
49 |
Correct |
45 ms |
5336 KB |
Output is correct |
50 |
Correct |
23 ms |
5844 KB |
Output is correct |
51 |
Correct |
22 ms |
4828 KB |
Output is correct |
52 |
Correct |
24 ms |
5800 KB |
Output is correct |
53 |
Correct |
20 ms |
5852 KB |
Output is correct |
54 |
Correct |
25 ms |
6620 KB |
Output is correct |
55 |
Correct |
36 ms |
5468 KB |
Output is correct |