简单的贪心算法
#include<bits/stdc++.h>
using namespace std;
struct StoreHouse{
double sum_price;
double sum;
double price;
};
bool cmp(const StoreHouse &s1,const StoreHouse &s2){
return s1.price>s2.price;
}
StoreHouse a[1005];
int main(){
int n,sum;
double money=0;
scanf("%d %d",&n,&sum);
for(int i=0;i<n;i++)
scanf("%lf",&a[i].sum);
for(int i=0;i<n;i++)
scanf("%lf",&a[i].sum_price);
for(int i=0;i<n;i++)
a[i].price=a[i].sum_price/a[i].sum;
sort(a,a+n,cmp);
int i=0;
while(sum>a[i].sum&&i<n){
money+=a[i].sum_price;
sum-=a[i].sum;
i++;
}
//printf("%d\n",i);
if(i<n){
money+=sum*a[i].price;
}
printf("%.2lf\n",money);
return 0;
}