#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
signed main()
{
int n, x;
cin >> n >> x;
vector<int>t(n);
rep(i,n) cin>>t[i];
vector<int>c;
vector<int>right(n);
for(int i = n-1; i >=0; i--)
{
int r = 1e10 - t[i];
if(!c.size()||r>c[c.size()-1]) c.push_back(r);
else *(lower_bound(c.begin(), c.end(), r)) = r;
right[i] = c.size();
}
c = vector<int>(n, 1e17);
int maxx = 0;
rep(i,n)
{
auto it = lower_bound(c.begin(), c.end(), t[i] - x);
int off = it - c.begin();
maxx=max(maxx, right[i] + (lower_bound(c.begin(), c.end(), t[i] - x) - c.begin()));
*(lower_bound(c.begin(), c.end(), t[i]-x)) = t[i] - x;
}
cout<<maxx<<"\n";
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:30:13: warning: unused variable 'off' [-Wunused-variable]
30 | int off = it - c.begin();
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
126 ms |
4964 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
33 ms |
1464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
69 ms |
2648 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |