You are viewing a single comment's thread. Return to all comments →
Priorty Queue used. Java. Minimum lines of code.
import java.util.Scanner; import java.util.PriorityQueue; public class Solution{ public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n = sc.nextInt(), k = sc.nextInt(), c= 0; PriorityQueue<Integer> p = new PriorityQueue<>(); while (n-- > 0) p.add(sc.nextInt()); while (p.size() >= 2 && p.peek() < k) { int min1 = p.remove(), min2 = p.remove(); p.add(min1 + 2*min2); c++; } System.out.println((p.size() <= 1 && p.peek() < k) ? -1 : c); sc.close(); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Jesse and Cookies
You are viewing a single comment's thread. Return to all comments →
Priorty Queue used. Java. Minimum lines of code.