-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBillDivision.java
43 lines (33 loc) · 1.07 KB
/
BillDivision.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.util.*;
public class BillDivision {
public static void bonAppetit(List<Integer> itemsCost, int k, int b) {
int notEatenId = 0, splitPrice = 0;
for (int i = 0; i < itemsCost.size(); i++) {
notEatenId = itemsCost.get(k);
if (itemsCost.get(i) == itemsCost.get(k)) {
continue;
} else {
splitPrice += itemsCost.get(i);
}
}
int total = splitPrice / 2;
int annaMoneyLeft = 0;
if (b > total) {
annaMoneyLeft = b - total;
System.out.println(annaMoneyLeft);
} else if (b == total) {
System.out.println("Bon Appetit");
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
List<Integer> itemsCost = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
itemsCost.add(in.nextInt());
}
int b = in.nextInt();
bonAppetit(itemsCost, k, b);
}
}