GE VernovaOA #1
The Best Subsequence || Find the minimum of special value of a subsequence
Estimated MediumJudge-ready
Topics (AI-labelled)Subsequences
Choose k elements, keeping their original order, so that the sum of the absolute differences between adjacent chosen values is minimized.
This site's standard input/output format and supplementary bounds are as described in this problem.
Input
The first line contains n k (1≤n≤800, 1≤k≤n); the next line contains n integers, |arr[i]|≤10^9.
Output
Output the minimum special value.
Example 1
Input:
5 2
9 5 1 4 9
Output:
0
Example 2
Input:
6 3
9 5 1 4 9 100
Output:
5
Example 3
Input:
1 1
-3
Output:
0
Editorial
Loading solution…