https://codeforces.com/contest/1400/problem/B
有一点很重要,s能用完就一定会用完,枚举我用几个s就好
#include<iostream> #include<cstring> #include<queue> #include<algorithm> using namespace std; typedef long long ll; ll t,p,f,cnta,cntb,s,w; int main(){ cin>>t; while(t--){ cin>>p>>f; cin>>cnta>>cntb; cin>>s>>w; ll ans = 0; if(s > w){ swap(s,w); swap(cnta,cntb); } for(ll i=0;i<=cnta && i*s <= p;i++){//我用i个s,他用cnta - i 个s ll k = cntb; ll b = min(k,(p-i*s)/w);//我用几个w k -= b; if( (cnta - i)*s > f ){//随从全用s ans = max(ans,i + f/s + b); } else{ ll c = min(k,(f - (cnta - i)*s) / w); ans = max(ans,c + cnta + b); } } cout<<ans<<endl; } return 0; }