You are viewing a single comment's thread. Return to all comments →
C#:
public static int cookies(int k, List<int> A) { var items = new PriorityQueue<int, int>(); for (int i = 0; i < A.Count; i++) { items.Enqueue(A[i], A[i]); } int count = 0; while (items.Count > 1 && items.Peek() < k){ var newItem = items.Dequeue() + (2 * items.Dequeue()); items.Enqueue(newItem, newItem); count++; } return items.Peek() < k ? -1 : count; }
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 →
C#: