#K63282. Emergency Department Patient Admission Simulation

    ID: 31719 Type: Default 1000ms 256MiB

Emergency Department Patient Admission Simulation

Emergency Department Patient Admission Simulation

In an Emergency Department (ED), patients arrive at various times each with an assigned severity level. The ED has a limited capacity (p). When a new patient arrives, if the ED is not full, the patient is admitted. If the ED is already full, the patient with the lowest severity is replaced by the new patient if the new patient's severity is strictly greater than the lowest severity in the ED. The final list of admitted patients is output in order of their arrival time.

This problem requires you to simulate the admission process and maintain a dynamic set of admitted patients using an efficient data structure, typically a min-heap, to track the patient with the least severity.

inputFormat

The input is given via standard input (stdin) in the following format:

The first line contains two integers (n) and (p), where (n) is the number of patients and (p) is the maximum capacity of the ED.

This is followed by (n) lines; each line contains two integers representing the arrival time and the severity of a patient.

outputFormat

Print the admitted patients to standard output (stdout). Each admitted patient is printed on a new line with two integers separated by a single space: the arrival time and the severity. The output must be sorted in increasing order of the arrival times.## sample

5 3
1 50
2 40
3 60
4 70
5 30
1 50

3 60 4 70

</p>