#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define pb push_back
#define gcd __gcd
#define endl "\n"
#define task "hihi"
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7, INF = 1e18 + 5;
int n, x, a[N], b[N];
int solve(){
int res = 0;
b[0] = -INF;
for(int i = 1; i <= n; i++) b[i] = INF;
for(int i = 1; i <= n; i++){
int lo = 0, hi = n, ans = -1;
while(lo <= hi){
int mid = (lo + hi) / 2;
if(b[mid] <= i * x - a[i]){
lo = mid + 1, ans = mid;
} else{
hi = mid - 1;
}
}
b[ans + 1] = min(i * x - a[i], b[ans + 1]);
res = max(res, ans + 1);
}
return res;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
cin >> n >> x;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cout << n - solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |