PAT1070. Mooncake (25)

include

include

include <stdio.h>

include <math.h>

using namespace std;
struct SS{
double s;
double p;
double si;
};
int n,d;
SS pro[1010];
bool cmp(const SS &a,const SS &b){
return a.si>b.si;
}
int main(){
cin>>n>>d;
for(int i=0;i<n;i++) cin>>pro[i].s;
for(int i=0;i<n;i++) {
cin>>pro[i].p;
if(fabs(pro[i].s)<1e-9){
pro[i].si=0;
}else pro[i].si=pro[i].p/pro[i].s;
}
sort(pro,pro+n,cmp);
int i=0;
double res=0;
while(d&&i<n){
if(pro[i].s<d){
d-=pro[i].s;
res+=pro[i].p;
i++;
}else{
res+=pro[i].si*d;
d=0;
}
}
printf("%.2f\n",res);
return 0;
}

posted @ 2016-04-12 13:54  Yellowman  阅读(123)  评论(0编辑  收藏  举报
TVRBMExqRXlPQzR5TXpjdU1UVTEK\n