#C3338. Maximize Beauty

    ID: 46754 Type: Default 1000ms 256MiB

Maximize Beauty

Maximize Beauty

Given N locations numbered from 1 to N and an array of integers representing the beauty values at each location, your task is to choose exactly M out of these N locations such that the sum of the beauty values of the chosen locations is maximized.

Note: It is always optimal to choose the M locations with the highest beauty values. Formally, if the beauty values are represented by an array \(b_1, b_2, \dots, b_N\), you need to select a subset of size M such that the sum \(\sum_{i \in S} b_i\) is maximized.

Input/Output Specifications: The problem requires you to read from stdin and write the result to stdout.

inputFormat

The first line of input contains two integers N and M separated by a space.

The second line contains N space-separated integers where the \(i\)-th integer represents the beauty value at the \(i\)-th location.

\(1 \le M \le N \le 10^5\) and the beauty values are positive integers.

outputFormat

Output a single integer which is the maximum possible sum of the beauty values by planting trees in M locations.

## sample
5 2
1 3 2 5 4
9