Advertisement
JouJoy

P

Dec 12th, 2021
600
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. #define ll long long
  4. ll r, curr_r;
  5. ll have[3], need[3], cnt[3], price[3];
  6. bool check(ll x)
  7. {
  8.     curr_r = r;
  9.     for (int i = 0; i < 3; i++)
  10.         need[i] = max(0LL, cnt[i] * x - have[i]);
  11.     for (int i = 0; i < 3; i++)
  12.         curr_r -= (need[i] * price[i]);
  13.     return (curr_r >= 0);
  14. }
  15. int main()
  16. {
  17.     string s;
  18.     cin >> s;
  19.     for (int i = 0; i < s.size(); i++)
  20.     {
  21.         if (s[i] == 'B')
  22.             cnt[0]++;
  23.         else if (s[i] == 'S')
  24.             cnt[1]++;
  25.         else
  26.             cnt[2]++;
  27.     }
  28.     cin >> have[0] >> have[1] >> have[2];
  29.     cin >> price[0] >> price[1] >> price[2] >> r;
  30.     ll lo = 0, hi = 1e15, mid;
  31.     while (hi - lo > 1)
  32.     {
  33.         mid = lo + (hi - lo) / 2;
  34.         if (check(mid))
  35.             lo = mid;
  36.         else
  37.             hi = mid - 1;
  38.     }
  39.     if (check(hi))
  40.         cout << hi;
  41.     else
  42.         cout << lo;
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement