Jesse and Cookies

Solutions This is a typical job for a priority queue. Basically, we maintain the least sweet cookie on top: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 priority_queue<int, deque<int>, greater<int>> cookies; while (N--) { cin >> tmp; cookies.push(tmp); } auto cnt = 0; while (cookies.size()>1 && cookies.top()<K) { const auto c1 = cookies.top(); cookies.pop(); const auto c2 = cookies.top(); cookies.pop(); cookies.push(c1 + 2*c2); ++cnt; } cout << ((cookies. [Read More]