#K34752. Circular Queue Simulation of Attendees
Circular Queue Simulation of Attendees
Circular Queue Simulation of Attendees
You are given N attendees and a buffer size K. The process begins by loading the first K attendees into a circular buffer. Then, the simulation proceeds in N steps. In each step, the attendee located at the current pointer (calculated as the pointer modulo K) is processed and appended to the result list.
If there are any remaining attendees beyond the initial buffer, the slot from which the attendee was just processed will immediately receive the next available attendee from the list. This continues until all N attendees have been processed. Finally, print the sequence representing the order in which the attendees were handled.
Mathematically, let \( \text{buffer}[i] \) denote the current element at position \(i\). For each step \(j = 0, 1, \dots, N-1\), the position accessed is \( i = j \mod K \), and if \(K+j < N\), then \( \text{buffer}[i] \) is replaced with the attendee at index \(K+j\).
inputFormat
The input consists of two parts:
- The first line contains two integers, N and K (with \(1 \le K \le N \le 10^5\)).
- The second line contains N space-separated integers representing the IDs of the attendees.
outputFormat
Output a single line containing N space-separated integers, which represent the order in which the attendees are processed.
## sample7 3
1 2 3 4 5 6 7
1 2 3 4 5 6 7