Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class P {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner in = new Scanner(System.in);
  8. String x = in.next();
  9.  
  10. int b = 0;
  11. int s = 0;
  12. int c = 0;
  13. for (int i = 0; i < x.length(); i++) {
  14.  
  15. if (x.charAt(i) == 'B') {
  16. b++;
  17. } else if (x.charAt(i) == 'S') {
  18. s++;
  19. } else {
  20. c++;
  21. }
  22.  
  23. }
  24.  
  25. int nb = in.nextInt();
  26. int ns = in.nextInt();
  27. int nc = in.nextInt();
  28. int pb = in.nextInt();
  29. int ps = in.nextInt();
  30. int pc = in.nextInt();
  31. long r = in.nextLong();
  32.  
  33. long left = 0;
  34. long right = r + 1;
  35. long mid = 0;
  36. long ans = 0;
  37. while (left <= right) {
  38.  
  39. mid = (left + right) / 2;
  40.  
  41.  
  42. long first = Math.max(0, b*mid-nb) * pb;
  43. long second = Math.max(0, s*mid-ns) * ps;
  44. long last = Math.max(0, c*mid-nc) * pc;
  45. long p = first + second + last;
  46.  
  47. if (p == r) {
  48. System.out.println(mid);
  49. return;
  50. }
  51. if (p > r) {
  52. right = mid - 1;
  53. } else {
  54. left = mid + 1;
  55. ans = mid;
  56. }
  57.  
  58. }
  59.  
  60. System.out.println(ans);
  61.  
  62. }
  63.  
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement