fork download
  1. #include <bits/stdc++.h>
  2. #define PowerUp ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0)
  3. #define ll long long
  4. #define line "\n"
  5. using namespace std;
  6.  
  7. struct burger
  8. {
  9. ll bun, susage, cheese;
  10. };
  11.  
  12. burger have, cost, recipe;
  13.  
  14. ll burger_cost(ll number)
  15. {
  16. ll total_cost = 0;
  17. ll bun_cost = max((((number * recipe.bun) - have.bun) * cost.bun), (ll)0);
  18. ll susage_cost = max((((number * recipe.susage) - have.susage) * cost.susage),(ll) 0);
  19. ll cheese_cost = max((((number * recipe.cheese) - have.cheese) * cost.cheese),(ll) 0);
  20. total_cost += bun_cost + susage_cost + cheese_cost;
  21. return total_cost;
  22. }
  23.  
  24. int main()
  25. {
  26. PowerUp;
  27. string s;
  28. ll budget;
  29.  
  30. cin>>s;
  31. cin >> have.bun >> have.susage >> have.cheese;
  32. cin >> cost.bun >> cost.susage >> cost.cheese;
  33. cin>>budget;
  34.  
  35. map<char,ll> mp;
  36. for(int i=0; i<s.size(); i++)
  37. {
  38. mp[s[i]]++;
  39. }
  40. recipe.bun = mp['B'];
  41. recipe.susage = mp['S'];
  42. recipe.cheese = mp['C'];
  43. ll left = 0, right = 1e12+1000, mid;
  44. while (left < right)
  45. {
  46. mid = (right - left) / 2 + left;
  47. if (burger_cost(mid)>budget)
  48. right = mid;
  49. else
  50. left = mid+1;
  51. }
  52. if (burger_cost(right)>budget)
  53. right--;
  54.  
  55. cout<<right;
  56. }
Success #stdin #stdout 0s 5288KB
stdin
Standard input is empty
stdout
1000000001000