#K63452. Maximum Priority Email Selection

    ID: 31756 Type: Default 1000ms 256MiB

Maximum Priority Email Selection

Maximum Priority Email Selection

You are given n email addresses with their corresponding priority scores and an integer m indicating the maximum number of emails that can be sent. Your task is to determine the maximum total priority score achievable by selecting m emails.

Formally, if the list of priority scores is \(s_1, s_2, \dots, s_n\) and after sorting in descending order they become \(S_1 \ge S_2 \ge \dots \ge S_n\), then the answer is:

i=1mSi\sum_{i=1}^{m} S_i

You should read the input from standard input (stdin) and write the output to standard output (stdout).

inputFormat

The first line of input contains two integers n and m separated by a space.

The next n lines each contain a string and an integer separated by a space, representing an email address and its corresponding priority score.

Constraints:

  • \(1 \le n \le 10^5\)
  • \(1 \le m \le n\)
  • Priority scores are non-negative integers.

outputFormat

Output a single integer representing the maximum total priority score by selecting m emails.

## sample
5 3
a@example.com 10
b@example.com 5
c@example.com 8
d@example.com 7
e@example.com 6
25

</p>