I have been getting runtime error on test case 41. I have been trying to figure out the cause, even rewrote my code, but can't seem to understand why I am getting the error. Here's my code 150627419
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 165 |
2 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
4 | adamant | 160 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
8 | Dominater069 | 154 |
8 | nor | 154 |
I have been getting runtime error on test case 41. I have been trying to figure out the cause, even rewrote my code, but can't seem to understand why I am getting the error. Here's my code 150627419
Название |
---|
Wild guess but.. I think you should not use 'return true' as your default value for sorting compare function. Because if two objects are identical, it should logically return false
yes u r right.Now it is giving TLE.The reason for TLE is that u only need to take distinct ci.Imagine if n=1e5 and all ci =1 then the for loop after sort will go for n*n time.
zzzzsust19
Yes, that's why I figured that if I order the soldiers in order of their cost (minimum to maximum) and then by the product of di * hi (maximum to minimum). It should optimize the problem. Then when I am looping from 0 to n soldiers, if costlst[soldier's cost] >= soldier's (di * hi), I can skip them
I am a bit confused, shouldn't it return true if they are equal, as they don't need to swap
I tried it and it actually worked, but why?
yes i m also bit confused that why the cmp function return value result in RE.Did u got the logic behind the RE.
Well maybe this might help : https://codeforces.me/blog/entry/70237
or if you want more serious explanation : https://codeforces.me/blog/entry/45084