ZeptoLab Code Rush 2015---C. Om Nom and Candies, zeptolab2015 --- c
A sweet little monster Om Nom loves candies very much. one day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. wocould you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. the first was full of blue candies and the second bag was full of red candies. om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.
Candies are the most important thing in the world, but on the other hand overeating is not good. om Nom knows if he eats more than C grams of candies, he will get sick. om Nom thinks that it isn' t proper to leave candy leftovers, so he can only eat a whole candy. om Nom is a great mathematician and he quickly determined how many candies of what type he shoshould eat in order to get the maximum number Of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.
Input
The single line contains five integers C, lower Hr, lower Hb, lower Wr, lower Wb (1 ≤ lower C, lower Hr, lower Hb, lower Wr, invalid Wb limit ≤ limit 109 ).
Output
Print a single integer-the maximum number of joy units that Om Nom can get.
Sample test (s)
Input
10 3 5 2 3
Output
16
Note
In the sample test Om Nom can eat two candies of each type and thus get 16 joy units.
If the W value of a certain sugar ≥C −−√ Then, you can enumerate the quantity of sugar.
If the W values of the two types of sugar are both ≤ C −−√ In this case, we assume that, Hb hybrid Wr <Hr hybrid Wb
Set the blue sugar to X, and X ≥ Wr , We divide X into two parts, X = Y + k hybrid Wr , Because Hb hybrid Wr <Hr hybrid Wb , So K parallel Wr The part is replaced with red sugar, which is more cost-effective. Therefore, in this case, the number of blue sugar should <Wr
Hb hybrid Wr> Hr hybrid Wb And Hb hybrid Wr = Hr hybrid Wb In the same way.
/*************************************** * *********************************> File Name: z-C.cpp> Author: ALex> Mail: zchao1995@gmail.com> Created Time: ******************************** **************************************** /# include <functional> # include <algorithm> # include <iostream> # include <fstream> # include <cstring> # include <cstdio> # include <cmath> # include <cstdlib> # include <queue> # include <stack> # include <map> # include <bitset> # include <set> # include <vector> using namespace std; const double pi = acos (-1.0); const int inf = 0x3f3f3f3f; const double eps = 1e-15; typedef long LL; typedef pair <int, int> PLL; int main () {ll c, Hr, Hb, Wr, Wb; while (cin> C> Hr> Hb> Wr> Wb) {if (C <Wr & C <Wb) {cout <0 <endl; continue;} if (C <Wr & C> = Wb) {cout <C/Wb * Hb <endl; continue;} if (C <Wb & C> = Wr) {cout <C/Wr * Hr <endl; continue;} LL ans = 0; for (LL I = 0; I * I <= C; ++ I) {if (C-I * Wb> = 0) {ans = max (ans, I * Hb + (C-I * Wb)/Wr * Hr );} if (C-I * Wr> = 0) {ans = max (ans, I * Hr + (C-I * Wr)/Wb * Hb );}} cout <ans <endl;} return 0 ;}