H. Hamburgers
传送门
分析:见代码
code:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int lo = 0, hi = 1e13, ans = 0;
string recipe;
int nb, ns, nc, pb ,ps, pc;
int r;
signed main() {
cin >> recipe;
cin >> nb >> ns >> nc;
cin >> pb >> ps >> pc;
cin >> r;
while (lo <= hi) {
int mid = (lo + hi) / 2;
int need_b=max(0LL, mid * (count(recipe.begin(),recipe.end(), 'B')) - nb);
int need_s=max(0LL, mid * (count(recipe.begin(),recipe.end(), 'S')) - ns);
int need_c=max(0LL, mid * (count(recipe.begin(),recipe.end(), 'C')) - nc);
int cost=need_b*pb+need_s*ps+need_c*pc;
if (cost<=r) {
ans=mid;
lo=mid+1;
} else {
hi=mid-1;
}
}
cout << ans << endl;
return 0;
}