• + 0 comments
    int cookies(int k, vector<int> arr) {
        priority_queue<int, vector<int>, greater<int>> pq(arr.begin(), arr.end());
        int count = 0;
    
        while (pq.size() > 1 && pq.top() < k)
        {
            int first = pq.top();
            pq.pop();
            int second = pq.top();
            pq.pop();
    
            pq.push(first + 2 * second);
            count++;
        }
        return (pq.top() >= k) ? count : -1;   
    }