#include <bits/stdc++.h>
using namespace std;
int get_first_lis(vector<int> v){
int n = (int)v.size();
if(n == 0) return 0;
vector<int> lis;
for(int i = 0 ; i < n ; i++){
int val = v[i];
auto q = lower_bound(lis.begin(),lis.end() , val);
if(q == lis.end()){
lis.emplace_back(val);
}
else{
*q = val;
}
}
int sz = (int)lis.size();
return sz;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n , x;
cin >> n >> x;
vector<int> v(n);
for(int i = 0 ; i < n ; i++){
cin >> v[i];
}
vector<int> f;
int best = 0;
for(int i = 0 ; i < n ; i++){
f.emplace_back(v[i]);
vector<int> s;
for(int j = i + 1 ; j < n ; j++){
if(v[j] + x > v[i]) s.emplace_back(v[j]);
}
int a = get_first_lis(f);
int b = get_first_lis(s);
best = max(best , a + b);
}
cout << best << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2091 ms |
2908 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2087 ms |
1072 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2093 ms |
1708 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |