A. Increasing Sequence
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output
A sequence a0,?a1,?...,?at?-?1 is called increasing if ai?-?1?<?ai for each i:?0?<?i?<?t.
You are given a sequence b0,?b1,?...,?bn?-?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 b0,?b1,?...,?bn?-?1 (1?≤?bi?≤?106).
Output
Output the minimal number of moves needed to make the sequence increasing.
Sample test(s)
input
4 2
1 3 3 2
output
3
/* ***********************************************
Author :
Created Time :2015/6/2 16:01:09
File Name :2.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;
bool cmp(int a,int b){
return a>b;
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int n,d;
while(cin>>n>>d){
int a,b=-INF;
int ans=0;
for(int i=1;i<=n;i++){
cin>>a;
if(a<=b){
int x=(b-a)/d+1;
//if((b-a)%d==0) x++;
ans+=x;
a+=x*d;
}
b=a;
}
cout<<ans<<endl;
}
return 0;
}贪心的策略