https://codeforces.com/problemset/problem/2055/D
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
using ll = long long;
using pii = pair<int, int>;
const double PI = acos(-1);
const int N =2e5+10;
const int mod = 1e9 + 7;
int a[N];
void solve(){
int n,k;
double l;
cin>>n>>k>>l;
for(int i=1;i<=n;i++)
cin>>a[i];
double now=0;
double ans=0;
if(a[1]>0){
ans+=a[1];
a[1]=0;
}
for(int i=1;i<=n;i++){
if(now>=l){
break;
}
if(a[i]<=now){
if((now-(a[i]+ans))<k){
now=min(now,(a[i]+ans))+k;
}
}
else{
if(a[i]-ans<=now){
now+=k;
}
else{
double t=(a[i]-ans-now);
ans+=t/2;
now+=t/2;
now+=k;
}
}
}
if(now<l){
ans+=(l-now);
}
cout<<ll(2*ans)<<endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int T = 1;
cin>>T;
while (T--) {
solve();
}
return 0;
}
每个稻草人都用上保证最优,在乌鸦左边的稻草人都是用过的,右边的是还没有用过的
标签:乌鸦,const,int,double,稻草人,using From: https://www.cnblogs.com/laileou/p/18687453