zzzzsust19's blog

By zzzzsust19, history, 3 years ago, In English

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

  • Vote: I like it
  • -10
  • Vote: I do not like it

»
3 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    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

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      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

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I am a bit confused, shouldn't it return true if they are equal, as they don't need to swap

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I tried it and it actually worked, but why?

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      yes i m also bit confused that why the cmp function return value result in RE.Did u got the logic behind the RE.

»
3 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Well maybe this might help : https://codeforces.me/blog/entry/70237

or if you want more serious explanation : https://codeforces.me/blog/entry/45084