Question: write in java 8 Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value K. To do this, Jesse

write in java 8

write in java 8 Jesse loves cookies. He wants the sweetness of

all his cookies to be greater than value K. To do this,

Jesse repeatedly mixes two cookies with the least sweetness. He creates a

special combined cookie with: sweetness= (1x Least sweet cookie + 2x 2ndleast sweet cookie). He repeats this procedure until all the cookies in

Jesse loves cookies. He wants the sweetness of all his cookies to be greater than value K. To do this, Jesse repeatedly mixes two cookies with the least sweetness. He creates a special combined cookie with: sweetness= (1x Least sweet cookie + 2x 2nd least sweet cookie). He repeats this procedure until all the cookies in his collection have a sweetness > K. You are given Jesse's cookies. Print the number of operations required to give the cookies a sweetness > K. Print 1 if this isn't possible. Input Format The first line consists of integers N, the number of cookies and K, the minimum required sweetness, separated by a space. The next line contains N integers describing the array A where A is the sweetness of the ith cookie in Jesse's collection. Constraints 1 K. Output 1 if this isn't possible. Sample Input 6 67 1 2 3 9 10 12 Sample Output 2 Explanation Combine the first two cookies to create a cookie with sweetness = 1x1 + 2 x 2 = 5 After this operation, the cookies are 3,5,9,10,12. Then, combine the cookies with sweetness 3 and sweetness 5, to create a cookie with resulting sweetness = 1 x 3 + 2 x 5 = 13 Now, the cookies are 9, 10, 12, 13. All the cookies have a sweetness > 7. Thus, 2 operations are required to increase the sweetness. > Current Buffer (saved locally, editable) Java 8 1 import java.io.*; 2 import java.math.*; 3 import java.text.*; 4 import java.util.*; 5 import java.util.regex.*; 6 7 public class Solution { 8 9 /* 10 * Complete the cookies function below. 11 12 static int cookies (int k, int[] A) { 13 /* 14 * Write your code here. 15 16 17 } 18 19 private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) throws IOException { BufferedWriter bufferedwriter = new BufferedWriter(new FileWriter(System.getenv ("OUTPUT_PATH"))); String[] nk = scanner.nextLine().split(" "); int n = Integer.parseInt(nk [O].trim()); int k = Integer.parseInt(nk[1].trim()); int[] A = new int[n]; String[] AItems = scanner.nextLine().split(" "); 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 } 47 for (int Altr = 0; Altr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!