bnu 45519

Om Nom and Candies

Time Limit: 1000ms
Memory Limit: 262144KB
This problem will be judged on  CodeForces. Original ID:  526C
64-bit integer IO format:  %I64d      Java class name:  (Any)
Type: 
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •                   
  • A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?

    One day, when he came to his friend Evan, Om Nom didn't find him at home but he found two bags with candies. The first was full of blue candies and the second bag was full of red candies. Om Nom knows that each red candy weighs Wr grams and each blue candy weighs Wb grams. Eating a single red candy gives Om Nom Hr joy units and eating a single blue candy gives Om Nom Hb joy units.

    Candies are the most important thing in the world, but on the other hand overeating is not good. Om Nom knows if he eats more than C grams of candies, he will get sick. Om Nom thinks that it isn't proper to leave candy leftovers, so he can only eat a whole candy. Om Nom is a great mathematician and he quickly determined how many candies of what type he should eat in order to get the maximum number of joy units. Can you repeat his achievement? You can assume that each bag contains more candies that Om Nom can eat.

    Input 

    The single line contains five integers C, Hr, Hb, Wr, Wb (1 ≤ C, Hr, Hb, Wr, Wb ≤ 109).

    Output 

    Print a single integer — the maximum number of joy units that Om Nom can get.

    Sample Input 

    Input
    10 3 5 2 3
    Output
    16

    以为用完全背包解决 自己还是太天真  暴力两次 j<100000纯属投机取巧 刚开始时间超限 就在j上做了点文章

    #include <stdio.h>

    #include "stdio.h"

    long long int max(long long int a,long long int b){return a>b?a:b;}


    int main()

    {

        long long int vmax,w1,w2,v1,v2,k,maxn=0;

        scanf("%lld%lld%lld%lld%lld",&vmax,&v1,&v2,&w1,&w2);

        k=vmax/w1;

        for(int j=0;j<=k&&j<=100000;j++)

            maxn=max(maxn,j*v1+(vmax-j*w1)/w2*v2);

        k=vmax/w2;

        for(int j=0;j<=k&&j<=100000;j++)

            maxn=max(maxn,j*v2+(vmax-j*w2)/w1*v1);

        printf("%lld\n",maxn);

        return 0;

    }

    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

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

    抵扣说明:

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

    余额充值