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 | 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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
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 |
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://mirror.codeforces.com/blog/entry/70237
or if you want more serious explanation : https://mirror.codeforces.com/blog/entry/45084