#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
vector<int> lis, rlis;
vector<int> maxlis(n), rmaxlis(n);
vector<int> baselis(n), rbaselis(n);
for(int i = 0; i < n; i++){
cin >> a[i];
auto it = lower_bound(lis.begin(), lis.end(), a[i]);
auto it2 = lower_bound(lis.begin(), lis.end(), a[i] + x);
if(it == lis.end()){
lis.push_back(a[i]);
maxlis[i] = lis.size();
baselis[i] = lis.size();
}
else{
maxlis[i] = it2 - lis.begin();
baselis[i] = it - lis.begin();
*it = a[i];
}
}
for(int i = n - 1; i >= 0; i--){
auto it = lower_bound(rlis.begin(), rlis.end(), -a[i]);
auto it2 = lower_bound(rlis.begin(), rlis.end(), -a[i] - x);
if(it == rlis.end()){
rlis.push_back(-a[i]);
rmaxlis[i] = rlis.size();
rbaselis[i] = rlis.size();
}
else{
rmaxlis[i] = it2 - rlis.begin();
rbaselis[i] = it - rlis.begin();
*it = -a[i];
}
}
int maxi = 0;
for(int i = 0; i < n; i++){
maxi = max(maxi, max(maxlis[i] + rbaselis[i] - 1, baselis[i] + rmaxlis[i] - 1));
}
cout << maxi << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
86 ms |
4176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
1360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
35 ms |
2384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |