#K52372. Maximum Different Pokémon Species

    ID: 29295 Type: Default 1000ms 256MiB

Maximum Different Pokémon Species

Maximum Different Pokémon Species

Sergey is on a quest to catch as many different Pokémon species as possible. He is given m habitats, with each habitat containing a certain number of different Pokémon species. However, due to time constraints, Sergey can only visit at most n habitats. To maximize the number of different Pokémon species he catches, he should choose the n habitats with the most species. Mathematically, if the number of species in each habitat is represented as \(s_1, s_2, \dots, s_m\), and after sorting in descending order they become \(s_{(1)} \ge s_{(2)} \ge \dots \ge s_{(m)}\), then the maximum species he can catch is given by:

[ \text{Max Species} = \sum_{i=1}^{n} s_{(i)} ]

Your task is to implement a program that reads the input, processes the data, and outputs the maximum number of different Pokémon species Sergey can catch.

inputFormat

The first line of input contains two space-separated integers \(m\) and \(n\), where \(m\) is the number of habitats and \(n\) is the maximum number of habitats Sergey can visit.

The second line contains \(m\) space-separated integers representing the number of different Pokémon species in each habitat.

outputFormat

Output a single integer representing the maximum number of different Pokémon species Sergey can catch by visiting at most \(n\) habitats.

## sample
5 3
8 12 7 10 15
37