shreybatra's blog

By shreybatra, history, 21 month(s) ago, In English,

Problem link — here

I found the editorial for this problem a little over the head. It made the question a little too complicated. I did it in a more easy way just by having two buckets S1 and S2. Start the series in descending order, to prevent some side cases and optimise the solution. Here is the logic: For each element i (1 <= i <= N), if the sum(S1)<=sum(S2), add the element in S1 or else add it in S2. At the end, all I had to do was calculate absolute difference of sum(S1)-sum(S2).


solution link — here

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

8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

shreybatra Your approach is greedy... I don't think it will necessarily give the optimal solution.