Why WA in this approach? (SAVKONO)

I was really Stuck in this Problem…
The Question is this:->CodeChef: Practical coding for everyone And my solution was this:->1nPIZe - Online C++0x Compiler & Debugging Tool - Ideone.com But if I change the while loop of this code to this-> >

ll count = 0, i = n;
while (z > 0 && !s.empty()) {
++count; --i;
auto it = --s.end();
z = z - it->first;
ll y = it->first;
y = y / 2;
if(y) {
s.insert(make_pair(y, i));
if(z > 0) {
std :: cout << “Evacuate” << std :: endl;
cout << count << endl;

IT Gives AC… I want to know what is the problem in my code… The second was written on the Editorial… Also using hashing it would be easy but I want to learn sets and also CC said to apply either sets or Priority Queue so I used this… THANKS!!!

there can be a situation where your “s” set is empty and you are not taking care of that in your ideone code

1 Like