Atcoder C - Half and Half

C - Half and Half


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.

Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

Constraints

  • 1A,B,C5000
  • 1X,Y105
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C X Y

Output

Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.


#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
int pra, prb, prc;
int x, y;
LL ans = 0;
int main()
{
	while (cin >> pra >> prb >> prc >> x >> y) {
		ans = 0;
		if (prc * 2 < pra + prb) {
			ans += min(x, y)*prc * 2;
			if (x > y)
				ans += (x - y)*pra;
			else ans += (y - x)*prb;
		} else {
			ans = x*pra + y*prb;
		}
		if (prc * 2 * max(x, y) < ans)
			ans = prc * 2 * max(x, y);
		cout << ans << endl;
	}
	return 0;
}
贪心算法,如果存在C的价格乘2低于A+B,对于A和B都要买的情况,全部选择C来进行购买。 之后再分类讨论就OK了。



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值