#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
//思路: 用结构体存储月饼 里面存储 月饼的数量 价格 和单价
//将月饼的单价进行排序
//根据月饼的需求 依次卖出价格从高到低的月饼
//终止条件为 某种月饼的数量大于还需要的月饼的数量 这时候 sum += 所需数量月饼 / 该种月饼的数量 * 该种月饼的价格
struct node{
double quantity;
double price;
double perprice;
};
bool cmp(struct node a, struct node b){
return a.perprice > b.perprice;
}
int main() {
int kind;
double need;
cin >> kind >> need;
vector<node> mooncake(kind);
for (int i = 0; i < kind; i++) {
cin >> mooncake[i].quantity;
}
for (int i = 0; i < kind; i++) {
cin >> mooncake[i].price;
mooncake[i].perprice = mooncake[i].price / mooncake[i].quantity;
}
sort(mooncake.begin(), mooncake.end(), cmp);
double Price = 0;
for (int i = 0; i < kind; i++) {
if (need > mooncake[i].quantity) {
need -= mooncake[i].quantity;
Price += mooncake[i].price;
}else{
Price += mooncake[i].price * need / mooncake[i].quantity;
break;
}
}
printf("%.2lf\n", Price);
return 0;
}
1020. 月饼 (25)
最新推荐文章于 2020-11-02 17:46:32 发布