-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Solution.java
29 lines (26 loc) · 891 Bytes
/
Solution.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
29
// github.com/RodneyShag
import java.util.Scanner;
// Although imprecise, this problem is intended to be solved using an "int" instead of a "double" to store dollar amounts.
public class Solution {
public static void main(String[] args) {
/* Read input and calcute chargedBill and actualBill */
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
int k = scan.nextInt();
int actualBill = 0;
for (int i = 0; i < n; i++) {
int price = scan.nextInt();
if (i != k) {
actualBill += price;
}
}
actualBill *= 0.5;
int chargedBill = scan.nextInt();
/* Print output */
if (chargedBill == actualBill) {
System.out.println("Bon Appetit");
} else {
System.out.println(chargedBill - actualBill);
}
}
}