Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- long long nb,ns,nc,pb,ps,pc,credit;
- long long rb = 0,rs = 0,rc = 0;
- bool yes (long long k) {
- long long needb = k * rb;
- long long needs = k * rs;
- long long needc = k * rc;
- needb -= nb;
- needs -= ns;
- needc -= nc;
- needb = max(needb,0LL);
- needs = max(needs,0LL);
- needc = max(needc,0LL);
- long long money = needb * pb + needc * pc + needs * ps;
- if (money <= credit) return true;
- else return false;
- }
- int main () {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- string s;
- cin >> s;
- for (int i = 0;i < (int) s.size(); ++i) {
- if (s[i] == 'B') {
- rb++;
- }
- if (s[i] == 'C') {
- rc++;
- }
- if (s[i] == 'S') {
- rs++;
- }
- }
- cin >> nb >> ns >> nc >> pb >> ps >> pc >> credit;
- long long l = 0,r = 1e13;
- long long res = 0;
- while (l <= r) {
- long long mid = l + (r - l) / 2;
- if (yes(mid)) {
- l = mid + 1;
- res = mid;
- } else {
- r = mid - 1;
- }
- }
- cout << res << '\n';
- }
- //Problem Link : https://codeforces.com/problemset/problem/371/C
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement