#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(ll i = 0; i < (n); ++i)
#define for1(i, n) for(ll i = 1; i <= (n); ++i)
#define chmin(a, b) ((a) = min(a, b))
#define dbg(x) cout << #x << " = " << (x) << endl;
using ll = long long;
const int oo = 1e7;
const int MAXN = 2e5 + 2;
ll n, m;
int a[MAXN];
#define mret return mem[i] =
int mem[MAXN];
int f(int i)
{
if (i == -1) return 0;
if (mem[i] != -1) return mem[i];
int ans = oo;
int dec;
// dbg(i)
for (int j = i; j >= 0; --j)
{
// dbg(j) dbg(a[j] + m) dbg(a[i + 1] - (i + 1 - j) * m)
if (a[j] + m >= a[i + 1] - (i + 1 - j) * m)
{
// dbg(j)
// chmin(ans, (i - j) + f(j - 1));
int tmp = (i - j) + f(j - 1);
if (tmp < ans) ans = tmp, dec = j;
}
}
// cout << endl;
// dbg(i) dbg(dec)
mret ans;
}
int main()
{
cin >> n >> m;
for1(i, n) cin >> a[i];
forn(i, n+2) mem[i] = -1;
// forn(i, n+1) f(i);
cout << f(n);
}
| # | 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... |