P27416 [AtCoder] Buildings are Colorful!
普及+
题目描述

Problem Description

Input Format

$ N $ $ K $ $ a_1 $ $ a_2 $ $ a_3 $ ... $ a_N $

Output Format

Output the minimum cost in one line.
Also, include a newline at the end.

Sample Input and Output

Sample Input #1

5 5
3949 3774 3598 3469 3424

Sample Output #1

1541

Sample Input #2

5 3
7 4 2 6 4

Sample Output #2

7

Notes/Hints

Constraints

  • $1\ <\ =\ K\ <\ =\ N\ <\ =\ 15$
  • $1\ <\ =\ a_i\ <\ =\ 10^9$

Scoring

Subtask 1 \[$ 120 $ points\]

  • $N\ =\ K$

Subtask 2 \[$ 90 $ points\]
- $N\ <\ =\ 5$
- $a_i\ <\ =\ 7$

Subtask 3 \[$ 140 $ points\]
- No additional constraints.

Sample Explanation 1

If the heights of the buildings are set to $3949,\ 3950,\ 3951,\ 3952,\ 3953$ from left to right, Takahashi can see all the buildings.

Sample Explanation 2

If the heights of the buildings are set to $7,\ 8,\ 2,\ 9,\ 4$ from left to right, the goal can be achieved with a cost of $ 7 $.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 5 3949 3774 3598 3469 3424
样例输出
1541