charany1's blog

By charany1, 10 years ago, In English

Hi there,

I am trying to solve this problem : http://codeforces.me/contest/302/problem/C, however even on reading the editorial I am not able to get how to solve it.

Editorial link.

Editorial says that it can be solved using dfs but I am not even able to figure out the graph in the problem.

Further, most of solutions I have read are doing this :

if((n is odd) || (n is even and #negatives is even)) ans= sum of absolute values of all numbers

else ans=sum of absolute values of all numbers-2*(abs(element with minimum absolute value)) ``

Can you please help me in understanding how this is working and how to apply dfs in this ?

Thanks in advance.

  • Vote: I like it
  • 0
  • Vote: I do not like it

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

I don't understand why you need dfs in this problem either. It can be solved with pure bruteforce. You can see my solution, maybe it will be helpful: 9638601