수도 요금 경쟁


Software Expert Academy [1284] 수도 요금 경쟁

문제보기
Alt text

소스코드

import java.util.Scanner;
 
public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
 
        for (int tc = 1; tc <= T; tc++) {
            int P = sc.nextInt();
            int Q = sc.nextInt();
            int R = sc.nextInt();
            int S = sc.nextInt();
            int W = sc.nextInt();
 
            int A = P * W;
            int B = Q;
            if (W > R) {
                int diff = W - R;
                B += diff * S;
            }
            int ans = Math.min(A, B);
            System.out.println("#" + tc + " " + ans);
        }
    }
}