Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- #define ll long long
- ll r, curr_r;
- ll have[3], need[3], cnt[3], price[3];
- bool check(ll x)
- {
- curr_r = r;
- for (int i = 0; i < 3; i++)
- need[i] = max(0LL, cnt[i] * x - have[i]);
- for (int i = 0; i < 3; i++)
- curr_r -= (need[i] * price[i]);
- return (curr_r >= 0);
- }
- int main()
- {
- string s;
- cin >> s;
- for (int i = 0; i < s.size(); i++)
- {
- if (s[i] == 'B')
- cnt[0]++;
- else if (s[i] == 'S')
- cnt[1]++;
- else
- cnt[2]++;
- }
- cin >> have[0] >> have[1] >> have[2];
- cin >> price[0] >> price[1] >> price[2] >> r;
- ll lo = 0, hi = 1e15, mid;
- while (hi - lo > 1)
- {
- mid = lo + (hi - lo) / 2;
- if (check(mid))
- lo = mid;
- else
- hi = mid - 1;
- }
- if (check(hi))
- cout << hi;
- else
- cout << lo;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement