Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя zzzzsust19

Автор zzzzsust19, история, 2 года назад, По-английски

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

  • Проголосовать: нравится
  • -10
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

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

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    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

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    2 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I tried it and it actually worked, but why?

    • »
      »
      »
      2 года назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

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

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

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