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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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.