连着两周忘打 ABC 了(雾
思路
早上新买的鸡蛋筐直接扔到队尾。
中午客人要 个蛋,就一个框一个框拿,直到拿够 个蛋。框里鸡蛋空了就踢掉,接着去拿下一筐。
晚上如果队头框的购买时间 加上 已经小于等于今天了,直接踢掉。因为后买的蛋肯定比先买的新鲜,所以只要发现一筐没过期的,它后面的肯定都没过期。
Code
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 10;
int a[N], b[N];
int sum[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n >> d;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
for (int i = 1; i <= n; i++) cin >> b[i];
int l = 1;
for (int i = 1; i <= n; i++) {
l += b[i];
if (i - d >= 1) l = max(l, sum[i - d] + 1);
}
cout << (l > sum[n] ? 0 : sum[n] - l + 1) << '\n';
}
return 0;
}