http://www.elijahqi.win/archives/3812
贪心
便是每种生物尽量从最小等级的生物获得能量。
前缀和优化
#include<bits/stdc++.h>
#define eps 1e-8
using namespace std;
const int N=1e5+10;
int a[N],r[N],n;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if(T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {if(ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
int main(){
// freopen("3.in","r",stdin);
n=read();a[0]=read();double sum=0;
for (int i=1;i<=n;++i) a[i]=read(),r[i]=read();int tot=0;
for (int i=1;i<=n;++i){
while(tot<=r[i]){
sum+=a[tot];++tot;
}sum-=a[i]*5;
if (sum<-eps) {puts("-1");return 0;}
}while(tot<=n) sum+=a[tot],++tot;
printf("%f\n",sum*0.2);
return 0;
}