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

题意:

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

思路:

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

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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值