Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class P {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String x = in.next();
- int b = 0;
- int s = 0;
- int c = 0;
- for (int i = 0; i < x.length(); i++) {
- if (x.charAt(i) == 'B') {
- b++;
- } else if (x.charAt(i) == 'S') {
- s++;
- } else {
- c++;
- }
- }
- int nb = in.nextInt();
- int ns = in.nextInt();
- int nc = in.nextInt();
- int pb = in.nextInt();
- int ps = in.nextInt();
- int pc = in.nextInt();
- long r = in.nextLong();
- long left = 0;
- long right = r + 1;
- long mid = 0;
- long ans = 0;
- while (left <= right) {
- mid = (left + right) / 2;
- long first = Math.max(0, b*mid-nb) * pb;
- long second = Math.max(0, s*mid-ns) * ps;
- long last = Math.max(0, c*mid-nc) * pc;
- long p = first + second + last;
- if (p == r) {
- System.out.println(mid);
- return;
- }
- if (p > r) {
- right = mid - 1;
- } else {
- left = mid + 1;
- ans = mid;
- }
- }
- System.out.println(ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement