Editorial for Max's Anger Contest Series 1 P5 - Slacking Subsequences
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
Realize a DP state:
: the minimum sum of absolute differences for the integer in the array with a subsequence of length .
Then, for each given state, consider choosing any integer in the array before the
Thus,
Time Complexity:
Subtask 2
Realize that the transition can be optimized with
- Maintain
for all integers that come before but have with at the index. - Maintain
for all integers that come before but have with at the index.
Then, for each given state,
Time Complexity:
Comments