P3984 高兴的津津 题解
Dijkstra_zyl · · 题解
P3984 高兴的津津 题解
上代码
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6+10;
int a[maxn];
int main(){
int n,t,Au = 0; cin >> n >> t;
for(int i = 1;i <= n;i++) cin >> a[i];
for(int i = 1;i < n;i++)//因为要用到a[i+1] 所以只枚举到n-1
Au += (a[i+1]-a[i] >= t) ? t : a[i+1]-a[i];
//若今天到明天新获的奖牌数(a[i+1]-a[i])>=高兴时间,则累加高兴时间,否则累加新的奖牌数
cout << Au+t;//最后再加上最后一次的高兴时间
return 0;
}