In a certain RPG, there are $$$n$$$ slimes lined up in a row, numbered from $$$1$$$ to $$$n$$$ from left to right. Each slime can be of water-type, fire-type, or elementless. The power of the $$$i$$$-th slime is represented by a signed integer $$$a_i$$$. Specifically:
As a player, you will use a water-type magic to attack these slimes. The mana cost to attack a single slime is determined as follows:
To minimize the total mana cost, you can perform at most $$$k$$$ merging operations before casting the magic:
After performing at most $$$k$$$ operations, you cast the magic. The total final cost will be the sum of the mana costs required to attack all remaining slimes.
Find the minimum possible total cost if you use an optimal strategy.
The first line contains two integers $$$n$$$ and $$$k$$$, representing the number of slimes and the maximum number of merging operations you can perform.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, representing the initial represented powers of the slimes.
Output a single integer, representing the minimum possible total cost.
3 110 -10 5
5
5 23 -5 4 -2 6
7
4 25 -5 8 -8
0
| Название |
|---|


