Boredom
Source: Codeforces 455A
- Read the problem and summarise the task requirements.
- Try to keep your response to a couple of sentences.
Solve the testcase
and comment on how the order of values in the sequence affects the answer.
- Summarise the testcase above, recording only the information that could conceivably affect the answer.
- What data structure might be useful to represent this information?
- Is it feasible to construct and query this data structure? Check the input constraints.
Let’s generalise from the sample testcases.
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?
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?
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.
- Why might this be a complication?
- Think about dependencies. Which moves affect which other moves?
We want to process the moves in some order.
Propose a natural order to consider the moves.
As you analyse the moves in this order, what values in the sequence are relevant at each step?
- Propose a subproblem specification which includes at least the step of this order that you are up to.
- If you knew the answers to all subproblems, how would you retrieve the overall answer?
- The subproblem specification needs to contain all the values relevant to the DP, “screening” off the need to look any further back. These values can be stored either in the dimensions (key) or in the body (value) of the state, depending on what direction of calculation we want to follow.
- Propose a recurrence to relate subproblems of this form to each other.
- Is your subproblem specification sufficient, that is, can you form a valid recurrence?
- Analyse the time complexity of your algorithm, and estimate the running time.
- If the algorithm is too slow, consider optimisations to reduce the number of subproblems or the work per subproblem.
Implement this algorithm in code.
- Reflector:
- What potential pitfalls can you think of?
- Write some tests to check for these pitfalls.
- Other group members:
- Write a program which solves the problem.
- A tip: if you loop through both indices and values, use different loop counters to distinguish between them.
- Run your tests and debug if necessary.
- Submit your program for judging!
For an extension, let’s consider if one of the very convenient constraints in the question was less convenient.
- Solve the problem with ai up to 1018.