Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autumn Festival. Many types of fillings and crusts can be found in traditional mooncakes according to the region ' s culture. Now given the inventory amounts and the prices of all kinds of the mooncakes, together with the maximum total demand of th E Market, your is supposed to tell the maximum profit the can is made.
Note:partial Inventory storage can be taken. The sample shows the following situation:given three kinds of mooncakes with inventory amounts being Ousand tons, and the prices being 7.5, 7.2, and 4.5, billion yuans. If the market demand can are at the very most thousand tons, the best we can do are to sell thousand tons of the second kind of mooncake, and thousand tons of the third kind. Hence The total profit is 7.2 + 4.5/2 = 9.45 (Billion Yuans).
Input Specification:
Each input file contains the one test case. The first line contains 2 positive integers N (<=1000), the number of different kinds of mooncakes, and D (<=500 thousand tons), the maximum total demand of the market. Then the second line gives the positive inventory amounts (in thousand tons), and the third line gives the positive prices (in billion yuans) of N kinds of mooncakes. All the numbers in a line is separated by a space.
Output Specification:
For each test case, print the maximum profit (in billion Yuans) on one line, accurate up to 2 decimal places.
Sample Input:
3 200
180 150 100
7.5 7.2 4.5
Sample Output:
9.45
Pit point: 1, this problem, it is best to make the variables are set to double. 2, the maximum total may be 0.
1#include <iostream>2 3#include <algorithm>4 5#include <iomanip>6 7 using namespacestd;8 9 Ten One structMoom A - { - the DoublePR; - - Doublecc; - + }; - + A at BOOLCMP (moom a,moom B) - - { - - returna.pr/a.cc>b.pr/b.cc; - in } - to + -Moom mm[ +]; the * $ Panax Notoginseng intMain () - the { + A intn,i; the + DoubleD; - $ while(cin>>N) $ - { - theCin>>D; - Wuyi the - for(i=0; i<n;i++) Wu - { About $ - -Cin>>mm[i].cc; - A } + the - $ for(i=0; i<n;i++) the the { the the - inCin>>mm[i].pr; the the } About the the theSort (mm,mm+n,cmp); + - the BayiI=0;Doublesum=0; the the while(true) - - { the the if(mm[i].cc==0) Break; the the if(d<=mm[i].cc) - the { the thesum=sum+d/mm[i].cc*mm[i].pr;94 the Break; the the }98 About Else - 101 {102 103d=d-mm[i].cc;104 thesum=sum+mm[i].pr;106 107i++;108 109 } the 111 } the 113 the thecout<<fixed<<setprecision (2) <<sum<<Endl; the 117 }118 119 return 0; - 121 }122 123 124 the View Code
Mooncake (sort + greedy)