#P9173. [COCI 2022/2023 #4] Zrinka

[COCI 2022/2023 #4] Zrinka

Problem Description

You are given two arrays of length nn and mm, and they consist only of 00 and 11.

Your task is to replace each 00 with an even number, and each 11 with an odd number.

After the replacement, both arrays should be non-decreasing, all elements should be greater than 00, 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+1n + 1 integers. The first one is n(n5000)n(n\leq 5000), and the others describe the first array.

The second line contains m+1m + 1 integers. The first one is m(m5000)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.

0
4 1 0 1 1
5
4 0 1 0 1
4 1 0 0 1
9
5 0 1 0 0 1
4 0 0 0 1
13

Hint

Explanation for Sample 11:

One feasible solution is: (),(1,2,3,5)(\varnothing),(1,2,3,5).

Explanation for Sample 22:

One feasible solution is: (2,3,4,5),(1,6,8,9)(2,3,4,5),(1,6,8,9).

Explanation for Sample 33:

One feasible solution is: (2,3,6,8,9),(4,10,12,13)(2, 3, 6, 8, 9),(4,10,12,13).

Subtask ID Additional Constraints Score
00 Sample only 00
11 n=0n=0 1515
22 The first array contains only 00 2020
33 n,m500n,m\leq 500
44 No additional constraints 77

Translated by ChatGPT 5