Here is the question_link
Here is my solution.
please guide me why my solution giving runtime error?
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3839 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3612 |
7 | Geothermal | 3569 |
8 | ecnerwala | 3494 |
9 | Um_nik | 3396 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | Um_nik | 164 |
2 | -is-this-fft- | 162 |
3 | maomao90 | 159 |
3 | atcoder_official | 159 |
5 | cry | 158 |
5 | awoo | 158 |
7 | adamant | 155 |
8 | nor | 154 |
9 | TheScrasse | 153 |
10 | Dominater069 | 152 |
Here is the question_link
Here is my solution.
please guide me why my solution giving runtime error?
Name |
---|
Interesting. Running gdb with a random input of n=10k
The issue is in your comparator. Removing it cures the program of the SIGSEGV. What also works is changing
a1[1] > a2[1]
toa1[1] >= a[2]
. This stackoverflow answer explains the reason.Edited to Add:
https://en.cppreference.com/w/cpp/algorithm/sort mentions less than for comparison function. You need a strict partial order.
You've done it wrong:)
There must be that classic link.
mach_vm_map(size=1152921513196781568) failed (error code=3) *** error: can't allocate region *** set a breakpoint in malloc_error_break to debug libc++abi.dylib: terminating with uncaught exception of type std::bad_alloc: std::bad_alloc
When i changed some parts of your code (not drastically) I've got this exception. To simplify it means that you ran out of memory at some stage. By doing some further research i came up to a conclusion that an error pops up at sorting with comparator stage.
Its a simple memory leak. You have to change your comparator and it'll most likely solve the problem. The above links will guide you.