Goldenfield19's blog

By Goldenfield19, history, 9 hours ago, In English

i starts from 1; Noticing that sum((-1^i) * v[i]) doesn't change overall, so we can construct b[i] = -1^i * v[i] and let the biggest ceil(n/2) elements be on the positive slot and then count the result

The ans would then be sum(positive half) + sum(negative half), as sum(negative half) = sum(b) — sum(positive half), so the answer is 2*sum(positive) — sum(b)

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

»
8 hours ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't get how people can think of such complicated answers during contest, The most logical way to think about it is that in order to change the sign of an element on an odd index you need to swap with an element of an even index and greedily keep swapping smallest elements of each group as long as you're getting +ve delta check my last submission.

  • »
    »
    6 hours ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    yeah I agree, the solution you gave is far more intuitive