#C8474. Maximum Array Sum with Limited Decrements

    ID: 52460 Type: Default 1000ms 256MiB

Maximum Array Sum with Limited Decrements

Maximum Array Sum with Limited Decrements

You are given an array of n integers and a non-negative integer k. You are allowed to perform at most k decrement operations, where each operation decreases the value of a chosen element by 1. The goal is to maximize the sum of the array after performing these operations.

However, note that because decrementing any positive number always reduces the sum, the optimal strategy in this problem is to avoid performing any decrement operations at all. In other words, the maximum array sum is simply the sum of the original array elements.

Formula: \( \text{Sum} = \sum_{i=1}^{n} a_i \)

inputFormat

The input is given via standard input (stdin). The first line contains two space-separated integers n and k, where n is the number of elements in the array and k is the maximum number of decrement operations allowed. The second line contains n space-separated integers representing the array elements.

outputFormat

Print a single integer to standard output (stdout): the maximum possible sum of the array after performing at most k decrement operations.## sample

5 0
5 6 7 8 9
35

</p>