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;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
ll min_cost(vector<ll> arr, ll k) {
ll n = arr.size();
// find the length of the longest decreasing subsequence
vector<ll> dp(n, -1);
ll lis = 0;
for (ll i = 0; i < n; i++) {
ll start = 0;
ll end = lis;
while (start < end) {
ll mid = start + (end - start) / 2;
if (arr[dp[mid]] + k * (i - dp[mid]) >= arr[i]) start = mid + 1;
else end = mid;
}
if (start != 0 || i == 0) {
dp[start] = i;
if (start == lis) ++lis;
}
}
return n - lis;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
ll n, m;
cin >> n >> m;
vector<ll> arr;
arr.push_back(0);
for (ll i = 0; i < n; i++) {
ll val;
cin >> val;
arr.push_back(val);
}
cout << min_cost(arr, m);
}
# | 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... |