Essam's blog

By Essam, history, 4 years ago, In English

Hello https://mirror.codeforces.com/contest/1392/problem/B I dont understand why my code fails? https://ideone.com/OvJGfP

Algo: if k is odd : then -=max from every element. if k is even: then dont do anything because the subtractions will eliminate each other like max-(max-x) = x

Thanks,

  • Vote: I like it
  • +5
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it +10 Vote: I do not like it

$$$k = 2$$$. input array: $$$[-199, 192]$$$

After first iteration, the array becomes: $$$[391, 0]$$$

After second iteration, $$$[0, 391]$$$

Hope you get the point.