Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
1.3 kB
29
Indexable
Never
import java.util.Scanner;

public class B {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int X = scanner.nextInt();

        int cups = 0;

        int balanceA = 0;
        int tempA = A;
        int lostA = 0;
        while (tempA >= 1){
            tempA--;
            lostA++;
            balanceA += 500;
            if (balanceA >= X){
                balanceA = 0;
                cups++;
                A = A - lostA;
                lostA = 0;
            }
        }

        int balanceB = 0;
        int tempB = B;
        int lostB = 0;
        while (tempB >= 1){
            tempB--;
            lostB++;
            balanceB += 1000;
            if (balanceB >= X){
                balanceB = 0;
                cups++;
                B = B - lostB;
                lostB = 0;
            }
        }

        int commonBalance = 0;
        while (B >= 1 && A >= 1){
            B--;
            A--;
            commonBalance += 1500;
            if (commonBalance >= X){
                commonBalance = 0;
                cups++;
            }
        }

        System.out.println(cups);
    }
}