传送门
送分呀,模拟一下就好了。。。
代码:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#define ll long long
using namespace std;
inline int read(){
int x=0;char ch=' ';int f=1;
while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
if(ch=='-')f=-1,ch=getchar();
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
return x*f;
}
int n,t;
int a[200001];
int main(){
n=read();t=read();
for(int i=1;i<=n;i++)a[i]=read();
int ans=0;
for(int i=1;i<n;i++){
if(a[i+1]-a[i]<=t)ans+=a[i+1]-a[i];
else{
ans+=t;
}
}
ans+=t;
printf("%d",ans);
return 0;
}