Here is a test case for which your output is wrong
1 1 10
Output should be
Cherry 6 but your Output is
You need to push z/2 in priority queue when the size of priority queue is 1.
Here is your code which gets accepted after that change
In your code when the priority queue becomes empty, you are simply adding that number but you are not inserting the halved of that number. Since when only one element is left, it will be definitely unique and hence it should be halved and added back to queue.
The code which got accepted after one change.
Missed that, thanks for the help.
Missed that, thanks for the help