Educational Codeforces Round 71 (Rated for Div. 2) A - There Are Two Types Of Burgers
原文链接:https://www.cnblogs.com/xwl3109377858/p/11404050.html
Educational Codeforces Round 71 (Rated for Div. 2)
A - There Are Two Types Of Burgers
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 b buns, p beef patties and f chicken cutlets in your restaurant. You can sell one hamburger for h dollars and one chicken burger for c dollars. Calculate the maximum profit you can achieve.
You have to answer t independent queries.
Input
The first line contains one integer t (1≤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
Note
In first query you have to sell two hamburgers and three chicken burgers. Your income is 2⋅5+3⋅10=40.
In second query you have to ell one hamburgers and two chicken burgers. Your income is 1⋅10+2⋅12=34.
In third query you can not create any type of burgers because because you have only one bun. So your income is zero.
题意:题目意思是给你若干个面包,牛肉,鸡排。两个面包和一个牛肉可以做成一个牛肉面包,
两个面包和一个鸡排可以做成一个鸡肉面包,两种面包有两个价值,问你最大利益。
思路:因为两种面包原料两个面包一样,我们只需要看肉的不同,哪种面包的价值更大,
优先做哪种面包,原料有多可以再做另一种面包,就可以达到最大利益,具体看代码。
1 #include<iostream>
2 #include<cstdio>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<map>
7 #include<set>
8 #include<vector>
9 #include<queue>
10 #include<stack>
11 #include<list>
12 using namespace std;
13 #define ll long long
14 const int mod=998244353;
15 const long long int inf=1e18+7;
16 //const int maxn=
17
18 int main()
19 {
20 ios::sync_with_stdio(false);
21 int T;
22 cin>>T;
23 int a,b,c;//a个面包,b个牛肉,c个鸡排
24 int x,y;//牛肉面包价格x,鸡肉面包价格y
25 while(T--)
26 {
27 cin>>a>>b>>c>>x>>y;
28 ll int sum=0;
29 if(x>=y)//做牛肉面包划算
30 {
31 sum+=min(a/2,b)*x;
32 a-=min(a/2,b)*2;
33
34 if(a>0)//剩下的做鸡肉面包
35 sum+=min(a/2,c)*y;
36 }
37 else//做鸡肉面包划算
38 {
39 sum+=min(a/2,c)*y;
40 a-=min(a/2,c)*2;
41
42 if(a>0)//剩下的做牛肉面包
43 sum+=min(a/2,b)*x;
44 }
45 cout<<sum<<endl;
46 }
47
48 return 0;
49 }