cswork / OA打开练习工作台

GE VernovaOA #1

The Best Subsequence || Find the minimum of special value of a subsequence

估计中等可在线判题

考点(AI 标注)子序列

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.

输入格式

The first line contains n k (1≤n≤800, 1≤k≤n); the next line contains n integers, |arr[i]|≤10^9.

输出格式

Output the minimum special value.

样例 1

输入:

5 2
9 5 1 4 9

输出:

0

样例 2

输入:

6 3
9 5 1 4 9 100

输出:

5

样例 3

输入:

1 1
-3

输出:

0