We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/*
* Complete the 'bonAppetit' function below.
*
* The function accepts following parameters:
* 1. INTEGER_ARRAY bill
* 2. INTEGER k
* 3. INTEGER b
*/
public static void bonAppetit(List<Integer> bill, int k, int b) {
int sum2=0;
int sum1=0;
int diff=0;
for(int i=0;i<bill.size();i++){
sum1=sum1+bill.get(i);
if(bill.get(i)!=bill.get(k)){
sum2=sum2+bill.get(i);
}
}
sum1=sum1/2;
sum2=sum2/2;
diff=sum1-sum2;
if(diff==b){
System.out.println("Bon Appetit");
}
else if(diff!=b){
System.out.println(diff);
}
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String[] firstMultipleInput = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");
int n = Integer.parseInt(firstMultipleInput[0]);
int k = Integer.parseInt(firstMultipleInput[1]);
List<Integer> bill = Stream.of(bufferedReader.readLine().replaceAll("\\s+$", "").split(" "))
.map(Integer::parseInt)
.collect(toList());
int b = Integer.parseInt(bufferedReader.readLine().trim());
Result.bonAppetit(bill, k, b);
bufferedReader.close();
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bill Division
You are viewing a single comment's thread. Return to all comments →
import java.io.; import java.math.; import java.security.; import java.text.; import java.util.; import java.util.concurrent.; import java.util.function.; import java.util.regex.; import java.util.stream.*; import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.toList;
class Result {
}
public class Solution { public static void main(String[] args) throws IOException { BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
}