Hamburgers
#include<bits/stdc++.h> using namespace std; char B='B',S='S',C='C'; string t; int nb,ns,nc,pb,ps,pc,len; long long r1; map<char,int> m; bool check(long long m1) { long long need=0; if(m1*m[B]>nb) need+=(m1*m[B]-nb)*pb; if(m1*m[S]>ns) need+=(m1*m[S]-ns)*ps; if(m1*m[C]>nc) need+=(m1*m[C]-nc)*pc; return need<=r1; } int main() { int num=0; cin>>t; len=t.length(); for(int i=0;i<len;i++) { m[t[i]]++; } cin>>nb>>ns>>nc>>pb>>ps>>pc>>r1; long long l=0,r=max(max(nb,ns),nc)+r1,mid; while(l<=r) { mid=(l+r)/2; if(check(mid)) { l=mid+1; } else r=mid-1; } cout<<r<<endl; return 0; }
样例