Here is the question_link
Here is my solution.
please guide me why my solution giving runtime error?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Here is the question_link
Here is my solution.
please guide me why my solution giving runtime error?
Название |
---|
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.