#C8202. Final Buffer State Simulation
Final Buffer State Simulation
Final Buffer State Simulation
You are given a fixed-size buffer with capacity \(N\). You will insert \(M\) integers sequentially into the buffer. When the buffer is not full, simply append the new entry. However, if the buffer is already full, you must remove the earliest (first) element and then append the new entry.
In other words, if the input sequence is \(a_1, a_2, \ldots, a_M\), then the final state of the buffer is:
- If \(M \leq N\): \(a_1, a_2, \ldots, a_M\)
- If \(M > N\): \(a_{M-N+1}, a_{M-N+2}, \ldots, a_M\)
Your task is to simulate the process and output the final state of the buffer as space-separated integers.
inputFormat
The first line of input contains two integers \(N\) and \(M\) separated by a space, where \(N\) is the size (capacity) of the buffer and \(M\) is the number of entries to insert.
The second line contains \(M\) space-separated integers representing the entries to be inserted in order.
outputFormat
Output a single line containing the final state of the buffer as \(N\) or fewer space-separated integers.
## sample5 7
1 2 3 4 5 6 7
3 4 5 6 7