AcWing 1556. 月饼
原题链接
简单
作者:
Value
,
2020-05-26 11:36:06
,
所有人可见
,
阅读 814
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
struct Cake{
double stock;
double value, avg;
};
Cake cake[N];
int n;
double request; // 需求量必须定义为浮点型
void read(){
cin >> n >> request;
for(int i = 0; i < n; i ++ ) cin >> cake[i].stock;
for(int i = 0; i < n; i ++ ){
cin >> cake[i].value;
cake[i].avg = cake[i].value / cake[i].stock;
}
}
bool cmp(Cake a, Cake b){
return a.avg > b.avg;
}
int main(){
read();
sort(cake, cake + n, cmp);
double res = 0.0;
for(int i = 0; i < n; i ++ ){
if(request >= cake[i].stock) res += cake[i].value, request -= cake[i].stock;
else{
res += request * cake[i].avg;
break;
}
}
printf("%.2lf\n", res);
return 0;
}