My Solution for problem Problem passes all test cases except 2 of them are giving WA and I have followed everything as in editorial and also checked for overflow still WA. Can anyone find error ? Thanks.
@rj25 actually multiset.erase(key) removes all elements equal to key. To remove a single instance, you can instead do multiset.erase(multiset.find(key)). Generally you should first check whether multiset.find(key) is past-the-end iterator, but key in guaranteed to exist in the multiset in this situation so it is not necessary. I made the change in your code, and it works- here ![]()
I have understood the solution,I just need to know where my solution is going wrong as it is passing almost all test cases.
I’ll have a look soon…
I’m out at the moment.
I used multiset for the first time so didn’t knew about it. I was stuck on this for hours. Thanks a lot man. 
No problem 
I didn’t know about this too, but managed to find the bug by comparing with some accepted solutions.