CF11A Increasing Sequence
入门题,就不解释了
题解:
算法复杂度为O(n)
#include <iostream>
#include <algorithm>
using namespace std;
int a[2001];
int main()
{
int n,b,ans;
cin>>n>>b;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=2;i<=n;i++)
{
if(a[i]<=a[i-1])
{
ans +=(a[i-1]-a[i])/b;
a[i]=a[i]+((a[i-1]-a[i])/b+1)*b;
ans++;
}
}
cout<<ans<<endl;
}