首页 > 代码库 > L2-003. 月饼

L2-003. 月饼

 

 

 

 

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
struct mooncake{
float price;
float reserve;
float allPrice;
bool operator < (const mooncake &a) const
{
return price > a.price;
}
}nowMoon[1001];   //i know how to use the struct
int main()
{
int n, d;
cin >> n >> d;
for(int i=0; i<n; i++)
cin >> nowMoon[i].reserve;
for(int i=0; i<n; i++)
{
cin >> nowMoon[i].allPrice;
nowMoon[i].price = nowMoon[i].allPrice/nowMoon[i].reserve;
}
sort(nowMoon, nowMoon+n);
int i=0;
float biggestIncome = 0;
while(d>0&&i<n)
{
if(d>=nowMoon[i].reserve)
{
biggestIncome = biggestIncome + nowMoon[i].allPrice;
d = d - nowMoon[i].reserve;
i++;
}
else
{
biggestIncome = biggestIncome + d * nowMoon[i].price;
break;
}
}
printf("%0.2f", biggestIncome);
return 0;
}  //so easy, i think you can understand without interpretation

L2-003. 月饼