Double Burgers help

My approach for this is same as many have done and maybe I’m missing something.
If anyone can provide a test case where this code fails, it would be a big help. I have also commented the code so its easier to understand.
https://www.codechef.com/viewsolution/46831647

Thanks

I tried many many cases , even random , but it showinfg same as mine .

may be @ssjgz can help ,some language issue or something

Yup I have also tried many cases . Even those which people commented on others’ posts regarding this problem. Everything seems correct so far .
@cubefreak777 or @ssjgz Please help if possible.

[simon@simon-laptop][20:17:33]
[~/devel/hackerrank/otherpeoples]>./compile-latest-cpp.sh 
Compiling vruttant1403-BURGER.cpp
+ g++ -std=c++14 vruttant1403-BURGER.cpp -O3 -g3 -Wall -Wextra -Wconversion -DONLINE_JUDGE -D_GLIBCXX_DEBUG -fsanitize=undefined -ftrapv
vruttant1403-BURGER.cpp: In function ‘void solve()’:
vruttant1403-BURGER.cpp:47:6: warning: unused variable ‘m’ [-Wunused-variable]
  int m=1;
      ^
+ set +x
Successful
[simon@simon-laptop][20:17:42]
[~/devel/hackerrank/otherpeoples]>echo "2
1 7
1 4" | ./a.out
/usr/include/c++/7/debug/safe_iterator.h:270:
Error: attempt to dereference a singular iterator.

Objects involved in the operation:
    iterator "this" @ 0x0x7ffcc5163e90 {
      type = __gnu_debug::_Safe_iterator<std::_Rb_tree_const_iterator<long long>, std::__debug::set<long long, std::less<long long>, std::allocator<long long> > > (mutable iterator);
      state = singular;
      references sequence with type 'std::__debug::set<long long, std::less<long long>, std::allocator<long long> >' @ 0x0x7ffcc5163f30
    }
Aborted (core dumped)

Error occurs on the last line of:

     it = prev(it);
        s.erase(it);        //erase from set as cant use same number again

        y-=(*it);

presumably because you’ve just used an iterator that you’ve invalidated.

Edit:

I’ve shown you this technique before - please don’t tag me on a Problem until you’ve tried it yourself :slight_smile:

1 Like

I understand… My bad for not noticing that error . I may have missed it while trying to correct the code. But, even after correcting it, it shows WA. I understand there was the iterator error.
https://www.codechef.com/viewsolution/46832400

1 Like