This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
#define ll long long
void solve() {
int n, h; cin >> n >> h;
vector<int> arr(n);
for (int i = 0; i < n; i++) cin >> arr[i];
// a[i] = i * h - arr[i];
// arr[j] - j * h >= arr[i] - i * h
// j * h - arr[j] <= i * h - arr[i]
// a[i] >= a[j] st j < i
// a[j] <= a[i]
vector<int> a(n);
for (int i = 0; i < n; i++) {
a[i] = (i + 1) * h - arr[i];
}
// reverse(all(a));
vector<int> dp;
for (int i : a) {
if (i < 0) continue;
int pos = lower_bound(all(dp), i + 1) - dp.begin();
if (pos == (int)dp.size()) {
dp.push_back(i);
} else {
dp[pos] = i;
}
}
cout << (n - (int)dp.size()) << endl;
// vector<int> dp(n + 1, 0);
// dp[0] = 0;
// for (int i = 1; i <= n; i++) {
// if (i * h >= arr[i]) {
// dp[i] = 1;
// } else {
// continue;
// }
// for (int j = i - 1; j >= 1; j--) {
// if (arr[j] >= arr[i]) {
// dp[i] = max(dp[i], dp[j] + 1);
// } else if (arr[j] + (i - j) * h >= arr[i]) {
// dp[i] = max(dp[i], dp[j] + 1);
// }
// }
// }
// int ans = 0;
// for (int i = 0; i <= n; i++) ans = max(ans, dp[i]);
// cout << (n - ans) << endl;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while (T--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |