-
Notifications
You must be signed in to change notification settings - Fork 3
/
TaumAndBirthday.java
28 lines (24 loc) · 1.12 KB
/
TaumAndBirthday.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// https://www.hackerrank.com/challenges/taum-and-bday/problem
package implimentation;
import java.util.Scanner;
public class TaumAndBirthday {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int queries = scanner.nextInt();
while (queries-- > 0) {
long numberOfBlackGifts = scanner.nextLong();
long numberOfWhiteGifts = scanner.nextLong();
long costBlackGift = scanner.nextLong();
long costWhiteGift = scanner.nextLong();
long conversionCost = scanner.nextLong();
System.out.println(minimumCost(numberOfBlackGifts, numberOfWhiteGifts,
costBlackGift, costWhiteGift, conversionCost)
);
}
}
private static long minimumCost(long blackGifts, long whiteGifts, long costBlack, long costWhite, long conversion) {
long minimumBlackGiftCost = Math.min(costBlack, costWhite + conversion);
long minimumWhiteGiftCost = Math.min(costWhite, costBlack + conversion);
return blackGifts * minimumBlackGiftCost + whiteGifts * minimumWhiteGiftCost;
}
}