#K83622. Maximum Elixir Potency
Maximum Elixir Potency
Maximum Elixir Potency
You are given n potion types, each with a specified potency value. Your task is to combine exactly k different potions such that the total potency value is maximized. The total potency is the sum of the potency values of the chosen potions.
Input: The first line contains two integers n and k. The second line contains n integers representing the potency values of each potion.
Output: Output a single integer which is the maximum total potency value obtained by summing the top k largest potencies.
The solution can be approached by first sorting the list of potencies in descending order and then summing the first k values.
inputFormat
The input is read from standard input (stdin) and consists of two lines:
- The first line contains two space-separated integers n (number of potion types) and k (number of potions to combine).
- The second line contains n space-separated integers representing the potency values of the potions.
outputFormat
Print out a single integer to standard output (stdout) which represents the maximum total potency value by selecting exactly k potions.
## sample5 3
3 7 10 2 5
22
</p>