Yu Gong Yishan (peaks)

Description


XX years ago, there was an old man named Yu Gong who was almost 90 years old. There is \(N\) li shan Road from his home to the city, which is very inconvenient for people to come and go.One day, Yu Gong summoned the whole family and said, "These mountains are blocking our door. We have to take a lot of wrong roads when we go out. Why don't we try our best to remove these mountains?" Yugong's sons and grandchildren all said, "You are right!" Finally they decided: to transport the rocks and soil from the mountain to the sea. The next day, Yu Gong took his family and started moving. But the Yugong family only used hoes and baskets to move the mountain, and the distance between the mountain and the sea was so far away that one person could not go back and forth twice a day. After a month of work, Dashan looks no different from before. But Yugong led the family, regardless of the heat and winter, greedy the dark and dig mountains every day. Until one day the god came here and was moved by Yu Gong, so he decided to help Yu Gong. The \(N\)-mile mountain road from Yugong’s house to the middle of the city is in a straight line. The altitude of the i-th mountain road is \(H_i\). If a section of mountain road with the same height is lower than it on both sides or the mountain boundary, then this section of mountain road will be Call it "Mountain Top". The god decided to use his divine power to lower the altitude of some mountain roads so that the number of mountain tops does not exceed K. But the god did not want to be too obvious and be discovered by Yu Gong, so he turned to you for help.
Request that the number of "mountains" does not exceed \(K\), and what is at least the sum of the heights of all mountain roads.

Format


Input

Two positive integers \(N\),\(K\) in the first line.
The next line of \(N\) positive integers Hi.

Output

A number, the smallest sum of all mountain roads' reduced height.

Sample


Input

12 1
1 2 3 3 3 2 1 3 2 2 1 2

Output

5

Sample Explanation

    * * *     *
  * * * * *   * * *   *
* * * * * * * * * * * * 
1 2 3 3 3 2 1 3 2 2 1 2

This is the shape of the previous mountain, with 3 summits.

    * * *     -
  * * * * *   - - -   -
* * * * * * * * * * * * 
1 2 3 3 3 2 1 1 1 1 1 1

This is after the gods used their divine power (‘-’ means they were dropped by the god’s divine power OOXX), only one mountain top remained.

Hint


\(100\%\): \(K \leq 25\), \(1 \leq H_i \leq 1000000\)
\(90\%\): \(N \leq 1000\)
\(100\%\) \(N \leq 100000\)

Sample Code


Code is not available!
posted @ 2020-10-14 01:09  Sample_Test  阅读(159)  评论(0编辑  收藏  举报