#include <iostream>
#include <vector>
using namespace std;
#define oo 1000000000
int main() {
int n, x; cin >> n >> x;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
int sz = 1;
vector<int> dp(n);
vector<int> c(n+1, oo);
c[0] = 0;
c[1] = v[0];
dp[0] = 1;
for (int i = 1; i < n; ++i) {
if (v[i] < c[1]) c[1] = v[i], dp[i] = 1;
else if (v[i] > c[sz]) c[sz+1] = v[i], dp[i] = ++sz;
else {
int k = lower_bound(c.begin(), c.end(), v[i]) - c.begin();
c[k] = v[i];
dp[i] = k;
}
}
int ans = dp[n-1];
c.assign(0, n+1);
c[0] = oo;
c[1] = v[n-1] + x;
dp[n-1] = 1;
sz = 1;
for (int i = n-2; i >= 0; --i){
if (v[i] > c[1]) ans = max(ans, dp[i]);
else if (v[i] < c[sz]) ans = max(ans, dp[i] + sz);
else{
int k = lower_bound(c.rbegin(), c.rend(), v[i]) - c.rbegin();
ans = max(ans, dp[i] + k - 1);
}
if (v[i] + x > c[1]) c[1] = v[i] + x;
else if (v[i] + x < c[sz]) c[sz+1] = v[i] + x;
else{
int k = lower_bound(c.rbegin(), c.rend(), v[i] + x) - c.rbegin();
c[k] = v[i] + x;
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
103 ms |
2612 KB |
Output is correct |
2 |
Correct |
101 ms |
2628 KB |
Output is correct |
3 |
Correct |
105 ms |
2604 KB |
Output is correct |
4 |
Correct |
125 ms |
2600 KB |
Output is correct |
5 |
Correct |
72 ms |
2616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
872 KB |
Output is correct |
2 |
Correct |
26 ms |
744 KB |
Output is correct |
3 |
Correct |
27 ms |
880 KB |
Output is correct |
4 |
Incorrect |
24 ms |
880 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
1452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |