F - Laminate Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 600

問題文

10^9N 列の白色グリッドのいくつかのマスを黒く塗って、アートを製作します。
現時点では、左から i 列目については下から H_i 個のマスを黒く塗り、その列の残りのマスは塗らない予定です。
アートの製作を開始する前に、あなたは K 個以下の列 (0 個でもよい) を選び、それらの列に対する H_i の値を 0 以上 10^9 以下の好きな整数に変更できます。
変更後の値は列ごとに個別に選べます。

その後、あなたは次の操作を繰り返すことで変更後のアートを製作します。

  • ある行の連続する 1 マス以上のマスを選んで黒く塗る。(すでに黒く塗られたマスを再び塗ってもよいが、塗らないことにしたマスを塗ってはならない。)

この操作を最小で何回行う必要があるか求めてください。

制約

  • 1 \leq N \leq 300
  • 0 \leq K \leq N
  • 1 \leq H_i \leq 10^9
  • 入力はすべて整数である。

入力

入力は以下の形式で標準入力から与えられる。

N K
H_1 H_2 ... H_N

出力

必要な最小の操作回数を出力せよ。


入力例 1

4 1
2 3 4 1

出力例 1

3

例えば、H_3 の値を 2 に変更した上で以下のような操作を行うと、3 回の操作で変更後のアートを製作することができます。

  • 下から 1 行目の左から 1 列目から 4 列目までのマスを黒く塗る。
  • 下から 2 行目の左から 1 列目から 3 列目までのマスを黒く塗る。
  • 下から 3 行目の左から 2 列目のマスを黒く塗る。

入力例 2

6 2
8 6 9 1 2 1

出力例 2

7

入力例 3

10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000

出力例 3

4999999996

Score : 600 points

Problem Statement

We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns.
The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column.
Before starting to work, you can choose at most K columns (possibly zero) and change the values of H_i for these columns to any integers of your choice between 0 and 10^9 (inclusive).
Different values can be chosen for different columns.

Then, you will create the modified artwork by repeating the following operation:

  • Choose one or more consecutive squares in one row and paint them black. (Squares already painted black can be painted again, but squares not to be painted according to the modified plan should not be painted.)

Find the minimum number of times you need to perform this operation.

Constraints

  • 1 \leq N \leq 300
  • 0 \leq K \leq N
  • 0 \leq H_i \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N K
H_1 H_2 ... H_N

Output

Print the minimum number of operations required.


Sample Input 1

4 1
2 3 4 1

Sample Output 1

3

For example, by changing the value of H_3 to 2, you can create the modified artwork by the following three operations:

  • Paint black the 1-st through 4-th squares from the left in the 1-st row from the bottom.
  • Paint black the 1-st through 3-rd squares from the left in the 2-nd row from the bottom.
  • Paint black the 2-nd square from the left in the 3-rd row from the bottom.

Sample Input 2

6 2
8 6 9 1 2 1

Sample Output 2

7

Sample Input 3

10 0
1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000

Sample Output 3

4999999996