Here is the question_link
Here is my solution.
please guide me why my solution giving runtime error?
# | 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 | 151 |
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.