lnzva's blog

By lnzva, 8 years ago, In English

Problem link Editorial Link

Here, it says- "First, place 0 as the first number. Next, for every following number ai + 1 we will select maximum possible number from numbers left, matching above constraints (in simple case it will be ai + 1, otherwise we will check if ai - 2 left, e.t.c)."

I can see that it works, ie it produces the correct answer. However, I can't quite understand why it works.

I'd be very glad if someone helped me out, explain why this greedy is correct-and what the thought process is for arriving at this particular solution.

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