Can anyone tell me , why I am getting runtime error on test 1 itself ?? Problem link->http://codeforces.me/problemset/problem/387/B Code link->http://pastebin.com/N3JKSVPj
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3821 |
3 | Benq | 3736 |
4 | Radewoosh | 3631 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3388 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Can anyone tell me , why I am getting runtime error on test 1 itself ?? Problem link->http://codeforces.me/problemset/problem/387/B Code link->http://pastebin.com/N3JKSVPj
Name |
---|
Run it through valgrind and you'll see a bunch of invalid read errors. You need to advance the iterator before you erase the element from the set. You can use the return value from set.erase() like this.
http://codeforces.me/submissions/rakcode1998.
First of all , Thanks for helping .. Secondly, Above is the link of my recent submission as per your advice . I have corrected this as you said yuizy but i am not getting anything apart from runtime error.. And added to this IS , that my code is perfectly running on my PC..
You still have the same issue — you're advancing the iterator after erasing the corresponding element from the set. The reason it works on your PC is that it's undefined behavior, and would most likely cause a runtime error on your PC as well with bigger inputs. It seems you didn't perhaps understand my code, so here's a link with a few alternative solutions to the issue as one of them might be easier to understand: http://stackoverflow.com/questions/2874441/deleting-elements-from-stl-set-while-iterating.
Thanks yuizy ..and sorry for late reply..