Codeforces-1207F A. There Are Two Types Of Burgers

A. There Are Two Types Of Burgers

time limit per test 1 second
memory limit per test 256 megabytes
inputstandard input
outputstandard output

There are two types of burgers in your restaurant — hamburgers and chicken burgers! To assemble a hamburger you need two buns and a beef patty. To assemble a chicken burger you need two buns and a chicken cutlet.

You have bb buns, pp beef patties and ff chicken cutlets in your restaurant. You can sell one hamburger for hh dollars and one chicken burger for cc dollars. Calculate the maximum profit you can achieve.

You have to answer tt independent queries.

Input
The first line contains one integer tt (1≤t≤1001≤t≤100) – the number of queries.

The first line of each query contains three integers b, p and f (1≤b, p, f≤100) — the number of buns, beef patties and chicken cutlets in your restaurant.

The second line of each query contains two integers h and c (1≤h, c≤100) — the hamburger and chicken burger prices in your restaurant.

Output
For each query print one integer — the maximum profit you can achieve.

Example

Input

3
15 2 3
5 10
7 5 2
10 12
1 100 100
100 100

Output

40
34
0

题意:

本题的题意是先输入一个整数表示测试样例,接下来的两行分别表示:第一行的三个整数分别表示有多少片面包,多少片牛肉,和多少片鸡肉,如果要做牛肉汉堡或者鸡肉汉堡都需要一片牛肉或者一片鸡肉再加两片面包,接下来一行分别表示牛肉堡或鸡肉堡能卖出的价钱,求出能卖出去的最大价值。

思路:

分如下几种情况使得价值最大,当面包片足够组装当前所有肉片时,直接把贵的全加上,当面包片不够时,则先组装价值最大的,再组装价值第二大的从而实现价值最大化。

扫描二维码关注公众号,回复: 9101338 查看本文章

AC代码如下:

#include<iostream>
using namespace std;
#define max(a,b) a>b?a:b;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int b, p, f, h,c;
		cin >> b >> p >> f;//菜,牛肉,鸡肉;
		cin >> h >> c;
		if (h >= c)
		{
			int x = b / 2;//两片面包的个数
			if (p >= x) {
				cout << x*h<<endl;
				//牛肉片足够多时
			}
			if (p < x)
			{//牛肉片不够时
				int a2=0;
				int a1 = p*h;
				if (f >= x - p)
				{//鸡肉片足够时
					a2 = c*(x - p);
					cout << a2 + a1 << endl;
				}
					if (f < x - p)
					{//鸡肉片不够时
						cout << f*c + a1 << endl;
		
					}
			}

		}
		else{
		//反之亦然
			int x1= b / 2;//两片面包的个数
			if (f>= x1) {
				cout << x1*c << endl;
			
			}
			if (f < x1)
			{
				int a21=0;
				int a11 = c*f;
				if (p >= x1 - f)
				{
					a21 = h*(x1 - f);
					cout << a21 + a11 << endl;
				}
				if (p< x1 - f)
				{
					cout << p*h + a11<<endl;	
				}
			}
		}
	}

	return 0;
}

发布了40 篇原创文章 · 获赞 10 · 访问量 2577

猜你喜欢

转载自blog.csdn.net/lsdstone/article/details/100609926