Boredom

Source: Codeforces 455A

  1. Read the problem and summarise the task requirements.
  2. Solve the testcase

    and comment on how the order of values in the sequence affects the answer.

  3. Summarise the testcase above, recording only the information that could conceivably affect the answer.

Let’s generalise from the sample testcases.

  1. If the sequence has several copies of the integers x − 1, x and x + 1 only, and your first move is to choose x for deletion, what total will you achieve?

  2. If the sequence is unrestricted and your first move is to choose x for deletion, what will (eventually) happen to any other copies of x in the array?

  3. Characterise the collection of scoring moves that can arise from any input.

One complication is that the effects of a move go “both ways”, that is, choosing x affects values both smaller and larger than x.

  1. Why might this be a complication?

We want to process the moves in some order.

  1. Propose a natural order to consider the moves.

  2. As you analyse the moves in this order, what values in the sequence are relevant at each step?

  3. Propose a subproblem specification which includes at least the step of this order that you are up to.
  4. Propose a recurrence to relate subproblems of this form to each other.
  5. Analyse the time complexity of your algorithm, and estimate the running time.
  6. Implement this algorithm in code.

  7. Submit your program for judging!

For an extension, let’s consider if one of the very convenient constraints in the question was less convenient.

  1. Solve the problem with ai up to 1018.