FOJ2252:Yu-Gi-Oh!

传送门

题意

分析

枚举合成ab的数量,在此基础上合成bc和ac,复杂度\(O(n)\)

trick

代码

#include<cstdio>
#include<algorithm>
using namespace std;


#define ll long long
int t;
ll a,b,c,ab,ac,bc,ans,ret;

int main()
{
    for(scanf("%d",&t);t--;)
    {
        scanf("%lld%lld%lld%lld%lld%lld",&a,&b,&c,&ab,&ac,&bc);
        ans=0;
        for(int i=0;i<=min(a,b);++i)
        {
            ret=i*ab;
            ll ret1=min(a-i,c)*ac+min(b-i,(c-min(a-i,c)))*bc;
            ll ret2=min(b-i,c)*bc+min(a-i,(c-min(b-i,c)))*ac;
            ret+=max(ret1,ret2);
            ans=max(ans,ret);
        }
        printf("%I64d\n",ans);
    }
}
/*
1
1 10 2
9 10 2
*/
posted @ 2017-04-17 15:26  遗风忘语  阅读(115)  评论(0编辑  收藏  举报