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;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n + 1];
a[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
n++;
int dp[n + 1];
dp[n - 1] = dp[n] = 0;
for (int i = n - 2; i >= 0; i--) {
dp[i] = 1e9;
if (a[i] >= a[i + 1] || a[i + 1] - a[i] <= m) {
dp[i] = dp[i + 1];
}
for (int j = i + 1; j < n; j++) {
if (j == n - 1 || a[j + 1] <= a[i] + 2 * m) {
dp[i] = min(dp[i], dp[j + 1] + j - i);
}
}
for (int j = i; j < n; j++) {
if (j == n - 1 || a[i] - i * m >= a[j + 1] - j * m || a[j + 1] - (a[i] + j * m - i * m) <= m) {
dp[i] = min(dp[i], dp[j + 1] + j - i);
}
}
}
cout << dp[0] << '\n';
return 0;
}
# | 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... |