#C3948. Maximum Team Strength
Maximum Team Strength
Maximum Team Strength
You are given a set of participants with their respective skill levels. Your task is to form a team consisting of exactly K participants such that the total team strength is maximized. The team strength is defined as the sum of the skill levels of the selected participants.
Formally, given:
- An integer \(N\) — the number of participants.
- An integer \(K\) — the number of participants to be chosen for the team.
- A list \(S\) of \(N\) integers where \(S_i\) represents the skill level of the \(i\)-th participant.
You need to select exactly \(K\) participants such that the sum of their skill levels is maximized. In other words, you should compute the sum of the \(K\) largest values in \(S\).
Note: It is guaranteed that \(1 \le K \le N\).
The result should be output as an integer representing the maximum team strength.
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two space-separated integers \(N\) and \(K\).
- The second line contains \(N\) space-separated integers representing the array \(S\) of skill levels.
outputFormat
Output the maximum possible team strength as a single integer to stdout.
## sample5 3
5 2 8 1 6
19
</p>