#K16141. Project Scheduling Profit Maximization

    ID: 24513 Type: Default 1000ms 256MiB

Project Scheduling Profit Maximization

Project Scheduling Profit Maximization

You are given several test cases. In each test case, there are N projects and an upper limit K on the number of projects that can be completed. Each project has a deadline D and a profit P. A project can be completed in one unit of time, and it must be completed at or before its deadline. The goal is to select at most K projects such that the total profit is maximized.

Formally, for each project, you can choose a time slot t such that:

\(1 \le t \le \min(D, K)\)

No two projects can be scheduled in the same time slot. Compute the maximum profit for each test case.

inputFormat

The input starts with a single integer T denoting the number of test cases. For each test case:

  • The first line contains two integers N and K where N is the number of projects and K is the maximum number of projects that can be completed.
  • The following N lines each contain two integers D and P representing the deadline and profit of a project respectively.

All input is read from standard input (stdin).

outputFormat

Output the maximum profit for each test case on a new line. All output is written to standard output (stdout).

## sample
2
4 2
4 20
1 10
1 40
1 30
3 1
2 100
2 10
1 20
60

100

</p>