一天,欧姆诺诺姆来到了朋友家里,他发现了许多糖果。有蓝色和红色两种。他知道每颗红色糖果重Wr克,每颗蓝色糖果重Wb克。吃一颗蓝色糖果会给他带来Hb的欢乐值,吃一颗红色糖果会给他带来Hr的欢乐值。
欧姆诺姆最多只能吃C克的糖果,而且每一颗糖果不能只吃一半。现在他想通过吃蓝色和红色的糖果来获得最大的欢乐值。
样例解释:每一种糖果吃两颗即可。
Input
单组测试数据。 输入占一行有四个整数C,Hr,Hb,Wr,Wb (1≤C,Hr,Hb,Wr,Wb≤10^9).
Output
输出最大可能获得的欢乐值。
Input示例
样例输入1 10 3 5 2 3
Output示例
样例输出1 16
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int main()
{
int c, hr, hb, wr, wb;
cin >> c >> hr >> hb >> wr >> wb;
long long int result = 0;
int end = sqrt(c)+1;
for(long long int i = 0; i < end; ++i)
{
if (i*wr <= c)
{
result = max(result, i*hr+(c-i*wr)/wb*hb);
}
if (i*wb <= c)
{
result = max(result, i*hb+(c-i*wb)/wr*hr);
}
}
cout << result << endl;
return 0;
}