#K57857. Maximizing Efficiency Points

    ID: 30513 Type: Default 1000ms 256MiB

Maximizing Efficiency Points

Maximizing Efficiency Points

Sophia has m study sessions available, and each session comes with certain efficiency points. She can attend at most t sessions in a day. Your task is to help her achieve the maximum total efficiency points by selecting sessions wisely.

The optimal strategy is to choose the t sessions with the highest efficiency points. Mathematically, if the efficiency points are represented as \(a_1, a_2, \dots, a_m\), then the answer is given by:

\( S = \sum_{i=1}^{t} a_i^* \)

where \( a_i^* \) are the top t efficiency points after sorting in descending order.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains two space-separated integers (m) and (t) (with (1 \leq t \leq m)).
  2. The second line contains (m) space-separated integers representing the efficiency points of each session.

outputFormat

Output a single integer on standard output (stdout) which is the maximum total efficiency points Sophia can achieve by attending up to (t) sessions.## sample

5 3
1 2 3 4 5
12