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
# | User | Rating |
---|---|---|
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 |
# | 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 |
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
Name |
---|
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.net/blog/entry/70237
or if you want more serious explanation : https://codeforces.net/blog/entry/45084