You are given an initial array X of size N, where Xi denotes the ith element.
You must perform Q operations. Each operation consists of:
The first line contains two integers, N and Q.
The second line contains N integers representing the initial elements.
The next Q lines each contain a single integer A.
For each operation, output the maximum element before insertion. If the array is empty, output -1.
Input:
2 3
1 3
5
2
4
Output:
3
5
2
Explanation:
Start with [1, 3]
Operation 1 (x = 5): output 3, remove it, insert 5 → [1, 5]
Operation 2 (x = 2): output 5, remove it, insert 2 → [1, 2]
Operation 3 (x = 4): output 2, remove it, insert 4 → [1, 4]
| Subtask | Score |
|---|---|
| 1 | 100 |