can somebody post the editorial for cook82c
I am also looking for it, but not able to find.
You just need two Stacks and a Queue.
-> First of all, get all element and keep it in first Stack.
-> Sort all with increasing order.
-> Have a queue.
Do this repetion with rule:
If queue empty and stack not empty, pop last element in stack and divide by two and keep in queue.
If queue not empty and stack not empty then:
a. If front element >= stack element: pop element in queue, divide by two, and push to queue again.
b. Else pop last element in stack, divide by two, and push to queue.
If stack empty and queue not empty, pop front element in queue and divide by two and push back to queue.
Else, all element already processed
*Note: keep all solution in second stack. Don’t queue an element if element/2 < 1.
Edit 1: First case miss type, change to “Queue empty and Stack not Empty”
I used a priority queue and got wrong ans. just insert all elements in a priority queue and output the max element in O(1) and keep on removing top element and inserting the half of it when the next query comes. here is the link to my code https://www.codechef.com/viewsolution/13705879
Here is my solution for COOK82C in a lot easier manner with the above mention approach.
This is O(NlogN + 63*N) right (in worst case)?
And also a small correction in first point,
- If queue is empty and stack is not empty*
thanks for the correction
Can someone post the solution based on priority queue? I used priority queue but got TLE.