Zrinka
Time limit1sMemory limit1024 MB
Assign distinct positive integers, even for each 0 and odd for each 1, so both arrays increase, and minimize the largest value used.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You are given two arrays of length and , each containing only and .
Replace every with a positive even integer and every with a positive odd integer. After the replacement, both arrays must be increasing, and each positive integer may be used at most once.
Since this would be too easy, the largest number you use must be as small as possible. Given the two arrays, output the minimum possible largest number.
Input
The first array has length (), and the second has length ().
The first line contains integers. The first integer is , and the rest are the elements of the first array.
The second line contains integers. The first integer is , and the rest are the elements of the second array.
Output
Print one positive integer on the first and only line: the answer to the question above.
Hint
Clarification of the second example: One of the possible solutions is and .
Clarification of the third example: One of the possible solutions is and .