#CCBCHBAHAI0000047. Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)
Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)
Mô phỏng danh sách tĩnh với Q lệnh insert/delete (Simulate a Fixed-Capacity List with Q Insert/Delete Commands)
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem
A fixed array has capacity and initial logical size , where
Its current elements are . Then commands are processed in their given order.
There are two command types:
I p x: insert at index . The command is valid exactly when
If valid, old elements at indices move one position right, is placed at , and increases by . Otherwise the command is ignored.
D p: delete the element at index . It is valid exactly when
If valid, elements to the right move one position left and decreases by . Otherwise the command is ignored.
After all commands, print the final logical size and the remaining elements.
Input
The first line contains integers . The second line contains the initial integers and may be empty when . Each of the next lines contains one command I p x or D p.
Output
Print the final logical size on the first line. If , print the current array on the second line.
Subtask
Subtask 1 (100 points): ; ; ; ; .
Example
Input
5 3 5
10 20 30
I 1 15
D 2
I 3 40
I 4 50
I 0 99
Output
5
10 15 30 40 50
Explanation
After the first four commands, the array is 10 15 30 40 50 and is full because . The final command I 0 99 is ignored because no capacity remains.