#TP0000015. Lập trình theo cặp (Pair Programming)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Lập trình theo cặp (Pair Programming)
Pair Programming
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Monocarp and Polycarp are editing the same program file. Initially, the file has lines. During each minute, exactly one of them performs an operation: appending a new line or editing an existing line.
Monocarp performs the ordered sequence , whereas Polycarp performs . An operation equal to appends a line. A positive value edits line , which is permitted only when the file currently contains at least lines.
They may take turns arbitrarily, but each person's operations must retain their original relative order. Construct a valid merged sequence containing all operations, or report that no such merge exists.
Input
The first line contains three integers : the initial number of lines and the respective numbers of operations performed by Monocarp and Polycarp.
The second line contains integers in Monocarp's operation order.
The third line contains integers in Polycarp's operation order.
Output
If a valid merge exists, print integers on one line, describing the operations in execution order. Any valid merge is accepted. Otherwise, print -1.
Subtasks
- Subtask 1 (20 points): ; ; for every element of both arrays.
- Subtask 2 (30 points): ; ; for every element of both arrays.
- Subtask 3 (50 points): ; ; for every element of both arrays.
Examples
Input
3 2 2
2 0
0 5
Output
2 0 0 5
Explanation
The file initially has lines. Monocarp must edit line and then append a line; Polycarp must append a line and then edit line . The first action is valid because . The two zeros increase the line count from to and then to . Finally, editing line becomes possible. The output preserves each programmer's action order. 0 2 0 5 is another valid answer.