Newcoder 143 J.plan(水~)

186 篇文章 0 订阅

Description

n n n个人住宿,有双人间和三人间,价格分别为 p 2 , p 3 p_2,p_3 p2,p3,问最小花费

Input

三个整数 n , p 2 , p 3 ( 1 ≤ n , p 2 , p 3 ≤ 1 0 9 ) n,p_2,p_3(1\le n,p_2,p_3\le 10^9) n,p2,p3(1n,p2,p3109)

Output

输出最小花费

Sample Input

4 2 3

Sample Output

4

Solution

绝大部分人会选择性价比高的房间住,最后由于人数原因可能会选择一个性价比低的房间,但是此时所选房间数量不会超过 3 3 3,小范围枚举,剩下放假全部选择性价比高的房间,更新最优解即可

Code

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int n,p2,p3;
	while(~scanf("%d%d%d",&n,&p2,&p3))
	{
		ll ans=2e18;
		for(int i=0;i<=3;i++)
			for(int j=0;j<=2;j++)
			{
				ll temp=(ll)i*p2+(ll)j*p3;
				int num=0;
				if(n-2*i-3*j>0)num=(n-2*i-3*j+5)/6;
				temp+=min(3ll*p2,2ll*p3)*num;
				ans=min(ans,temp);
			}
		printf("%lld\n",ans);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值