#K73542. Room Assignment for Patients
Room Assignment for Patients
Room Assignment for Patients
You are given a hospital with r available rooms and a list of requests. Each request is either "doctor" or "patient". When a "doctor" request is encountered, the next available room (with the smallest number) is marked as a doctor's office. When a "patient" request is encountered, the next available room (with a higher number than any previously allocated room) is assigned to the patient. If no room is available for a patient, output -1 for that patient.
Note: Even though the number of doctors d is provided as input, it does not affect the room assignment process aside from the requests that explicitly mark a room as a doctor's office.
The room numbers are 1-indexed. After processing all requests, output the assigned room numbers for each patient request in the order they appear.
Example:
Input: r = 5, d = 2, requests = ["doctor", "patient", "patient", "doctor", "patient", "patient", "patient"] Output: [2, 3, 5, -1, -1]
inputFormat
The input is given via standard input in the following format:
- The first line contains two integers r and d, separated by a space, representing the number of rooms and the number of available doctors respectively.
- The second line contains a single integer n, the number of requests.
- The next n lines each contain a string: either "doctor" or "patient".
outputFormat
Output the room assignments for each patient request on a single line, separated by a space. If a patient cannot be assigned a room, output -1 in its place. There should be no output for doctor requests.
## sample5 2
7
doctor
patient
patient
doctor
patient
patient
patient
2 3 5 -1 -1
</p>