#K88597. Baton Passing Sequence
Baton Passing Sequence
Baton Passing Sequence
In this problem, you are given a list of employee IDs arranged in segments forming a circle. However, some employees may be absent. Your task is to compute the baton passing sequence by removing the absent employees from the list and appending the first present employee at the end to complete the cycle. Formally, let (E = [e_1, e_2, \dots, e_N]) be the list of employees and let (A) be the set of absent employee IDs. The resulting sequence (S) is defined as follows: [ S = [s_1, s_2, \dots, s_k, s_1] \quad \text{where} \quad {s_1, s_2, \dots, s_k} = { e \in E \mid e \notin A }. ] If all employees are absent, the sequence is empty. This problem simulates a baton passing game requiring careful filtering and cycle completion.
inputFormat
The first line contains an integer (T) representing the number of test cases. For each test case, the input consists of:
- A line with an integer (N), the number of segments (employees).
- A line with (N) space-separated integers, representing the employee IDs.
- A line with an integer (M), the number of absent employees.
- A line with (M) space-separated integers representing the absent employee IDs (if (M = 0), this line will be empty).
outputFormat
For each test case, output a single line containing the final baton passing sequence. The employee IDs should be printed in order, separated by a single space. If no employee is present (i.e., all are absent), output an empty line.## sample
3
5
101 102 103 104 105
2
102 104
4
201 202 203 204
0
4
201 202 203 204
4
201 202 203 204
101 103 105 101
201 202 203 204 201
</p>