Skip to content

Commit f09cde6

Browse files
authored
Create BonAppetit.java
1 parent 1eed98a commit f09cde6

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

BonAppetit.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import java.io.*;
2+
import java.math.*;
3+
import java.security.*;
4+
import java.text.*;
5+
import java.util.*;
6+
import java.util.concurrent.*;
7+
import java.util.function.*;
8+
import java.util.regex.*;
9+
import java.util.stream.*;
10+
import static java.util.stream.Collectors.joining;
11+
import static java.util.stream.Collectors.toList;
12+
13+
public class Solution {
14+
15+
// O(n) Time, O(1) Space
16+
static void bonAppetit(List<Integer> bill, int k, int b) {
17+
18+
int realBill = 0;
19+
20+
for (int i = 0; i < bill.size(); i++) {
21+
if (i == k) continue;
22+
realBill += bill.get(i);
23+
}
24+
25+
realBill /= 2;
26+
27+
if (realBill == b) System.out.println("Bon Appetit");
28+
else System.out.println(b - realBill);
29+
30+
}
31+
32+
public static void main(String[] args) throws IOException {
33+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
34+
35+
String[] nk = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
36+
37+
int n = Integer.parseInt(nk[0]);
38+
39+
int k = Integer.parseInt(nk[1]);
40+
41+
List<Integer> bill = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
42+
.map(Integer::parseInt)
43+
.collect(toList());
44+
45+
int b = Integer.parseInt(bufferedReader.readLine().trim());
46+
47+
bonAppetit(bill, k, b);
48+
49+
bufferedReader.close();
50+
}
51+
}

0 commit comments

Comments
 (0)