A sequence a 0, a 1, …, a t - 1 is called increasing if a i - 1 < a i for each i: 0 < i < t.
You are given a sequence b 0, b 1, …, b n - 1 and a positive integer d. In each move you may choose one element of the given sequence and add d to it. What is the least number of moves required to make the given sequence increasing?
Input
The first line of the input contains two integer numbers n and d (2 ≤ n ≤ 2000, 1 ≤ d ≤ 106). The second line contains space separated sequence b 0, b 1, …, b n - 1 (1 ≤ b i ≤ 106).
Output
Output the minimal number of moves needed to make the sequence increasing.
Examples
inputCopy
4 2
1 3 3 2
outputCopy
3
题意:
操作是把一个数加d,求最少多少次操作使得序列严格递增
思路:
直接模拟
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
int a[2005];
int main() {
int n,d;scanf("%d%d",&n,&d);
for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
int ans = 0;
for(int i = 2;i <= n;i++) {
if(a[i] <= a[i - 1]) {
int num = a[i - 1] - a[i];
ans += num / d + 1;
a[i] += num / d * d + d;
}
}
printf("%d\n",ans);
return 0;
}