Codeforces problem 1299 C TLE on test case10

Getting TLE on 10th case for problem 1299 C water balance.

@piyush.bansal8158625,
In the while loop, when the else case is hit, what is happening is that you are hoping 2 elements and pushing 2 elements, effectively not decreasing the size of priority_queue at all, thus the while loop will be an infinite loop, giving TLE.

https://codeforces.com/contest/1299/submission/75775866
But I am breaking out of that while loop using break. If it didn’t come out of while then it not haved 9 test cases.
Its going wrong in 10th test caseTLE

In the later two while loops could be O(n^2) giving TLE, as s.size() may be O(n) and while(y–) could also be O(n), giving n^2 in worst case. More like O(n/2 * n/2) may be.

Ok. In stack I have say x element with A as their average and B times need to be printed in final ans.

So how would I print the answer.
I need to have a loop for stack and one loop for printing. Please suggest some dits for passing the asnwer

@piyush.bansal8158625,
You can try reading it’s Editorial.

I have read that page earlier.
Please refer to Apaar bhaiya solution and he explained same logic ,difference is he is using index pairs and I am using exact count rather indexes. Please figure out the difference between his and mine code except that set pair diff.
https://codeforces.com/contest/1299/submission/70764469

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.