#C7654. Combined BST Operations

    ID: 51549 Type: Default 1000ms 256MiB

Combined BST Operations

Combined BST Operations

You are given an initial binary search tree (BST) represented by a sorted list of unique integers. Two players, Monocarp and Polycarp, each perform a series of operations on the BST. An operation is represented by an integer: a positive value indicates insertion of that number into the BST, while a negative value indicates deletion of the absolute value if it exists.

Your task is to merge these two sequences of operations into a single sequence by alternating between Monocarp’s and Polycarp’s operations. Start with Monocarp’s first operation, then Polycarp’s first operation, and continue alternately. If one sequence finishes before the other, append the remaining operations from the other sequence.

Note: The BST simulation is conceptual. You only need to output the merged operation sequence.

inputFormat

The input is read from stdin and consists of multiple test cases. The first line contains an integer t — the number of test cases. Each test case is defined as follows:

  • A line containing two integers n and k, where n is the number of nodes in the initial BST and k is an extra parameter (unused in the merging process).
  • A line containing n space-separated integers in sorted order representing the initial BST nodes.
  • A line containing an integer m — the number of operations performed by Monocarp, followed by a line with m space-separated integers representing these operations.
  • A line containing an integer p — the number of operations performed by Polycarp, followed by a line with p space-separated integers representing these operations.

outputFormat

For each test case, output a single line (to stdout) containing the merged sequence of operations as space-separated integers.

## sample
1
3 10
3 5 7
3
5 -5 9
3
6 -6 8
5 6 -5 -6 9 8

</p>