#include "bits/stdc++.h"
using namespace std;
#define int long long
const int inf = 1e9;
const int ms = 2e5 + 5;
int seg[4*ms], n;
void upd(int pos, int val, int l=0, int r=n-1, int idx=0){
if(l == r){
seg[idx] = val;
return;
}
int m = (l+r)/2;
if(pos <=m ) upd(pos, val, l, m, 2*idx + 1);
else upd(pos, val, m+1, r, 2*idx + 2);
seg[idx] = max(seg[2*idx + 1], seg[2*idx +2]);
}
int qry(int L, int R, int l=0, int r=n-1 ,int idx=0){
if(l > R || r < L) return 0;
if(r <= R && l >= L) return seg[idx];
int m = (l + r)/2;
return max(qry(L, R, l, m, 2*idx + 1), qry(L, R, m+1, r, 2*idx + 2));
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
int m;
cin >> n >> m;
vector<int> ord, v(n);
for(int i=0; i<n; i++) cin >> v[i];
ord = v;
sort(ord.begin(), ord.end());
ord.erase(unique(ord.begin(), ord.end()), ord.end());
int ans = 0;
for(int i=0; i<n; i++){
int l = lower_bound(ord.begin(), ord.end(), v[i] - m) - ord.begin();
int mx = qry(l, n-1) + 1;
ans = max(ans, mx);
int id = lower_bound(ord.begin(), ord.end(), v[i]) -ord.begin();
upd(id, mx);
}
cout << n - ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |