洛谷P16426
这道题就是一道典型的贪心,我们只需要让公鸡与母鸡相邻就好了喵。
但是要注意的一点就是egg们的孵化时间不一定小于 ,所以要特判一下的。
然后关键点就在后来下蛋数量,每相邻的一对小鸡们在 时间内孵的蛋为这个式子:
最后累加起来就好了喵,还要注意开long long哦
代码如下
#include <bits/stdc++.h>
//天翼3G太快辣
#define pb push_back
#define endl '\n'
#define NaHCO3 return
#define qwq 0;
#define Skywings
#define maxn 1000010
#define int long long
using namespace std;
int n, t, a[maxn], ans;
signed main() {
cin >> n >> t;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
if (a[i] >= t || a[i+1] >= t) continue;
ans += (t - max(a[i], a[i+1]));
}
cout << ans << endl;
NaHCO3 qwq
}