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 <algorithm>
#include <cassert>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
cin.tie(0); iostream::sync_with_stdio(false);
int n, m; cin >> n >> m;
const ll NEGINF = -1 - (n+1)*m;
vector<ll> a(n+2);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
a[i] -= i*m;
}
a[n+1] = NEGINF;
vector<int> dp(n+2);
for (int i = n; i >= 0; --i) {
int j = i+1;
while (a[j] > a[i])
++j;
dp[i] = dp[j] + j - i - 1;
ll maxval = NEGINF;
for (int j = i+1; j <= n+1; ++j) {
if (maxval < a[j] && a[j] <= a[i]) {
dp[i] = min(dp[i], dp[j] + j - i - 1);
}
maxval = max(maxval, a[j]);
}
}
cout << dp[0] << endl;
}
# | 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... |