#K85067. Select Top-K Data Points

    ID: 36559 Type: Default 1000ms 256MiB

Select Top-K Data Points

Select Top-K Data Points

You are given n data points, each with a timestamp and an importance score. Your task is to select exactly k data points such that:

  • The selected data points have the highest importance scores.
  • If two data points have the same importance score, the one with the smaller timestamp is preferred.

Formally, given a list of data points \( (t_i, s_i) \) where \( t_i \) is the timestamp and \( s_i \) is the importance score, you should sort the data points according to \( s_i \) in descending order and then by \( t_i \) in ascending order. Output the first \( k \) data points from this sorted order.

inputFormat

The first line of input contains two integers n and k where n is the number of data points and k is the number of data points to select. The following n lines each contain two space-separated integers: timestamp and importance score.

outputFormat

Output exactly k lines. Each line should contain two integers representing the timestamp and importance score of one of the selected data points, in the order they are selected.

## sample
5 3
1 100
2 200
3 100
4 300
5 200
4 300

2 200 5 200

</p>