In past few days I have faced this problem very frequently. Implementing same Logic with set gives AC where as vector implementation gives TLE OR MLE.
I just changed the set implementation to set in order to check the running time.
Above is the example of MLE v/s AC.
If anyone could tell me what I am mising...
Thanks in Advance.
q.erase(q.begin()) in vector is O(n)
Edit: to be more specific, it is linear on the number of elements after the erased element, so it's O(1) if you erase from the end of the vector only.
set is O(log(n)) wherever the element is
OKay. But Why MLE in second case??
Im not sure, but there are differences between the 2 codes other than set/vector swap.
Maybe that led to the loop not finishing correctly.
Nope, checked it myself as well.
yeah.
For the second one (MLE) you are pushing repeated elements so it becomes exponential. With set that doesn't matter because a set has unique elements. Your vector solution passes if you sort and use unique to remove repeated elements. http://codeforces.me/contest/1072/submission/45192350
okay. thanks mate.