ZeptoLab Code Rush 2015
C
Om Nom and Candies
Codeforces
2000
原题
← BD →
翻译中…

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. Would you succeed with the same task if you were on his place?

翻译中…

image

翻译中…

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 $*W*_{*r*}$ grams and each blue candy weighs $*W*_{*b*}$ grams. Eating a single red candy gives Om Nom $*H*_{*r*}$ joy units and eating a single blue candy gives Om Nom $*H*_{*b*}$ 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 should 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*, *H*_{*r*}, *H*_{*b*}, *W*_{*r*}, *W*_{*b*}$ ($1 ≤ *C*, *H*_{*r*}, *H*_{*b*}, *W*_{*r*}, *W*_{*b*} ≤ 10^{9}$).

翻译中…

Output

翻译中…

Print a single integer — the maximum number of joy units that Om Nom can get.

翻译中…

Note

翻译中…

In the sample test Om Nom can eat two candies of each type and thus get $16$ joy units.

翻译中…

样例

Input #1
10 3 5 2 3
Output #1
16
InputCopy OutputCopy
题目信息
题号
526C
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。