#include <algorithm>
#include <cstdio>
using namespace std;
struct mooncake {
double store;
double sell;
double price;
} cake[1010];
bool cmp(mooncake a, mooncake b) { return a.price > b.price; }
int main() {
int n;
double D;
scanf("%d%lf", &n, &D);
for (int i = 0; i < n; i++) {
scanf("%lf", &cake[i].store);
}
sort(cake, cake + n, cmp);
double ans = 0;
for (int i = 0; i < n; i++) {
if (cake[i].store <= D) {
D -= cake[i].store;
ans += cake[i].sell;
} else {
ans += cake[i].price * D;
break;
}
}
printf("%.2f\n", ans);
return 0;
}
//月饼利润最大化
最新推荐文章于 2025-06-30 08:17:20 发布
本文探讨了一种商业场景下利用排序算法优化库存管理的问题。通过读取商品库存并根据价格进行降序排列,实现了快速定位高价值商品。在库存不足时,算法能有效地计算出总销售额,体现了排序算法在实际业务中的高效应用。
3万+

被折叠的 条评论
为什么被折叠?



