#K11031. Minimum Effort to Clear Dungeon

    ID: 23378 Type: Default 1000ms 256MiB

Minimum Effort to Clear Dungeon

Minimum Effort to Clear Dungeon

You are trapped in a dungeon consisting of n rooms, each harboring a certain number of enemies. Additionally, you possess p magic potions. When used in a room, a magic potion completely eliminates all the enemies in that room so that no effort is required to clear it.

Your task is to minimize the total effort required to clear all the rooms in the dungeon. The effort for a room without a potion is equal to the number of enemies in that room. To achieve the minimum effort, you should use the potions on the rooms with the highest numbers of enemies. Mathematically, if the enemies in each room are represented as \(e_1, e_2, \dots, e_n\) and after sorting them in descending order as \(e_{(1)} \ge e_{(2)} \ge \cdots \ge e_{(n)}\), then the minimum effort is

[ \text{Effort} = \sum_{i=p+1}^{n} e_{(i)}, \quad \text{if } p < n, \quad \text{and } 0 \text{ otherwise.} ]

Determine and output this minimum total effort.

inputFormat

The input is read from stdin and follows this format:

  • The first line contains two integers, n (the number of rooms) and p (the number of available magic potions).
  • The second line contains n space-separated integers, where the i-th integer represents the number of enemies in the i-th room.

outputFormat

Output a single integer to stdout representing the minimum effort required to clear all the rooms.

## sample
5 2
4 2 3 5 8
9