-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
27 lines (24 loc) · 781 Bytes
/
Solution.java
File metadata and controls
27 lines (24 loc) · 781 Bytes
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
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int notEat = sc.nextInt();
Integer[] items = new Integer[n];
for (int i = 0; i < items.length; i++) {
items[i] = sc.nextInt();
}
int charge = sc.nextInt();
sc.close();
bonAppetit(Arrays.asList(items), notEat, charge);
}
static void bonAppetit(List<Integer> bill, int k, int b) {
int sum = 0;
for (int i = 0; i < bill.size(); i++) {
if (i != k) sum += bill.get(i);
}
System.out.println((sum / 2 == b) ? "Bon Appetit" : b - sum / 2);
}
}