【Henu ACM Round#19 E】 Om Nom and Candies

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

紫书上的原题; [链接](http://www.cnblogs.com/AWCXV/p/8036874.html)

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N = 1e5;

ll m,c1,c2,v1,v2;

int main()
{
    #ifdef LOCAL_DEFINE
        freopen("rush_in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(0),cin.tie(0);
    cin >> m >> c1 >> c2 >> v1 >> v2;
    ll ans = 0;
    if (m/v1 <=(int)1e7){
        for (int i = 0;i <= m/v1;i++){
            ll temp = 1LL*i*c1;
            ll temp2 = 1LL*c2*((m-1LL*i*v1)/v2);
            ans= max(ans,temp+temp2);
        }
    }else if (m/v2<=(int)1e7){
        for (int i = 0;i <= m/v2;i++){
            ll temp = 1LL*i*c2;
            ll temp2 = 1LL*c1*((m-i*v2)/v1);
            ans= max(ans,temp+temp2);
        }
    }else{
        if (c1*v2>c2*v1){
            for (int i = 0;i<=v1 ;i++){
                ll now = 1LL*i*c2;
                ll V = 1LL*i*v2;
                if (m-V<0) break;
                ll now1 = 1LL*((m-V)/v1)*c1;
                ans = max(ans,now+now1);
            }
        }else{
            for (int i = 0;i<=v2 ;i++){
                ll now = 1LL*i*c1;
                ll V = 1LL*i*v1;
                if (m-V<0) break;
                ll now1 = 1LL*((m-V)/v2)*c2;
                ans = max(ans,now+now1);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/8398295.html