Guessing Answers
Time limit1sMemory limit1024 MB
Given the correct answers and the set of problems guessed correctly, build an answer sequence where consecutive answers differ and exactly the listed problems are correct.
- Level
Medium6 of 10
- Topics
- Greedy, Implementation, Array, Brute force
- Solved
- No attempts yet
Problem
Yunee did not study for the final exam. So Yunee decided to guess the answers to all problems in the final exam. The final exam consists of single choice questions numbered from to , each with a choice of to .
Yunee gets anxious when the answers to two successive problems are the same. So Yunee always selects an answer different from the answer to the previous problem (except for the first problem). After submitting the answers, Yunee received the grading result, which stated whether each answer was correct.
Given the correct answers to all problems and the problems that Yunee guessed correctly, reconstruct a possible sequence of Yunee's answers. It is guaranteed that at least one such sequence exists for each input.
Input
The first line contains two integers and . is the total number of problems. is the number of problems that Yunee guessed correctly.
The second line contains integers from to . The -th integer represents the correct answer to the -th problem.
The third line contains distinct integers from to . They represent the problems that Yunee guessed correctly.
Output
Output a possible sequence of Yunee's answers. Each number should be separated by a blank.