#K13751. Maximum Card Power

    ID: 23982 Type: Default 1000ms 256MiB

Maximum Card Power

Maximum Card Power

You are given a collection of cards, each with an integer power value. Your task is to select exactly k cards (or all the cards if k is greater than the number of cards) such that the sum of their power values is maximized.

Formally, given an array \(C = [c_1, c_2, \dots, c_n]\) and an integer \(k\), you need to compute: \[ sum = \sum_{i=1}^{min(n, k)} c'_i \] where \(c'_i\) are the card powers sorted in descending order.

If the input list is empty or if \(k = 0\), output 0.

inputFormat

The first line of input contains two integers, \(n\) and \(k\), where \(n\) is the number of cards and \(k\) is the number of cards to pick.

The second line contains \(n\) space-separated integers representing the power values of the cards. If \(n = 0\), the second line may be empty.

outputFormat

Output a single integer representing the maximum total power level achievable by selecting \(k\) cards.

## sample
6 3
1 3 5 2 8 7
20