P9173 [COCI 2022/2023 #4] Zrinka

Description

You are given two arrays of length $n$ and $m$, and they consist only of $0$ and $1$. Your task is to replace each $0$ with an even number, and each $1$ with an odd number. After the replacement, both arrays should be non-decreasing, all elements should be greater than $0$, and you may use each positive integer at most once. The largest number used should be as small as possible.

Input Format

The first line contains $n + 1$ integers. The first one is $n(n\leq 5000)$, and the others describe the first array. The second line contains $m + 1$ integers. The first one is $m(m\leq 5000)$, and the others describe the second array.

Output Format

Output one positive integer on one line, which is the largest number.

Explanation/Hint

Explanation for Sample $1$: One feasible solution is: $(\varnothing),(1,2,3,5)$. Explanation for Sample $2$: One feasible solution is: $(2,3,4,5),(1,6,8,9)$. Explanation for Sample $3$: One feasible solution is: $(2, 3, 6, 8, 9),(4,10,12,13)$. | Subtask ID | Additional Constraints | Score | | :-: | :-: | :-: | | $0$ | Sample only | $0$ | | $1$ | $n=0$ | $15$ | | $2$ | The first array contains only $0$ | $20$ | | $3$ | $n,m\leq 500$ | $20$ | | $4$ | No additional constraints | $7$ | Translated by ChatGPT 5