When I tried this part of the code:
int x=*(s.rbegin());
while(!s.empty()&&0<x)
{
s.erase(x);
x=*(s.rbegin());
}
It runs into an infinite loop because it doesn't actually erase anything when I call erase. This seems weird because *(s.rbegin()) should definitely be in s.