Can anyone tell me , why I am getting runtime error on test 1 itself ?? Problem link->http://codeforces.net/problemset/problem/387/B Code link->http://pastebin.com/N3JKSVPj
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Can anyone tell me , why I am getting runtime error on test 1 itself ?? Problem link->http://codeforces.net/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.net/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..