#K96242. Taco: Maximum Concurrent File Size

    ID: 39043 Type: Default 1000ms 256MiB

Taco: Maximum Concurrent File Size

Taco: Maximum Concurrent File Size

You are given n files, each with two attributes: its size and the required number of computers to process it. The server can process at most k files concurrently. In order to optimize processing, the server picks files based on the following criteria:

  • Files requiring fewer computers are given higher priority.
  • If two files require the same number of computers, the file with the larger size is chosen first.

Your task is to select at most k files following the above criteria, and output the sum of their sizes.

Note: Although each file has a computer requirement, the server does not consider the sum of requirements. It only selects the top k files after sorting by the criteria.

The sorting criteria can be formally described as sorting the files by the tuple \( (\text{computers required}, -\text{size}) \).

inputFormat

The first line contains two integers n and k (1 ≤ n, k ≤ 105), where n is the number of files and k is the maximum number of files that can be processed concurrently.

The next n lines each contain two integers. The first integer is the file's size, and the second is the number of computers required to process the file.

It is guaranteed that all input values are integers.

outputFormat

Output a single integer, which is the maximum total size of files that the server will process concurrently.

## sample
3 2
10 1
20 2
30 1
40