Advertisement
newb_ie

Untitled

Sep 21st, 2021
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. long long nb,ns,nc,pb,ps,pc,credit;
  5. long long rb = 0,rs = 0,rc = 0;
  6.  
  7. bool yes (long long k) {
  8. long long needb = k * rb;
  9. long long needs = k * rs;
  10. long long needc = k * rc;
  11. needb -= nb;
  12. needs -= ns;
  13. needc -= nc;
  14. needb = max(needb,0LL);
  15. needs = max(needs,0LL);
  16. needc = max(needc,0LL);
  17. long long money = needb * pb + needc * pc + needs * ps;
  18. if (money <= credit) return true;
  19. else return false;
  20. }
  21.  
  22. int main () {
  23. ios::sync_with_stdio(false);
  24. cin.tie(nullptr);
  25. cout.tie(nullptr);
  26. string s;
  27. cin >> s;
  28. for (int i = 0;i < (int) s.size(); ++i) {
  29. if (s[i] == 'B') {
  30. rb++;
  31. }
  32. if (s[i] == 'C') {
  33. rc++;
  34. }
  35. if (s[i] == 'S') {
  36. rs++;
  37. }
  38. }
  39. cin >> nb >> ns >> nc >> pb >> ps >> pc >> credit;
  40. long long l = 0,r = 1e13;
  41. long long res = 0;
  42. while (l <= r) {
  43. long long mid = l + (r - l) / 2;
  44. if (yes(mid)) {
  45. l = mid + 1;
  46. res = mid;
  47. } else {
  48. r = mid - 1;
  49. }
  50. }
  51. cout << res << '\n';
  52. }
  53.  
  54. //Problem Link : https://codeforces.com/problemset/problem/371/C
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement