PivotOJ

Zrinka

시간 제한: 1000ms메모리 제한: 1024MB출처: COCI 2022-2023BOJ 27548

문제

You are given two arrays of length nn and mm respectively, which consist only of 00’s and 11’s.

Your task is to replace every zero with an even positive integer and every one with an odd positive integer. After replacements both arrays should be increasing and you can use each postive integers at most once.

As this would be to easy, you are asked to do it such that the largest number you use is as small as possible.

Given two arrays, output the minimum possible largest number that needs to be used.

입력

The first array is of length nn (0 ≤ n ≤ 5\,000), the second is of length mm (1 ≤ m ≤ 5\,000).

The first line consists of n+1n + 1 integers, first being nn, and others describing the first array.

The second line consists of m+1m + 1 integers, first being mm, and others describing the second array.

출력

The first and only line should contain a positive integer, the answer to the question above.

힌트

Clarification of the second example: One of the possible solutions is (2,3,4,5)(2, 3, 4, 5) and (1,6,8,9)(1, 6, 8, 9).

Clarification of the third example: One of the possible solutions is (2,3,6,8,9)(2, 3, 6, 8, 9) and (4,10,12,13)(4, 10, 12, 13).

예제

예제 1

입력
0
4 1 0 1 1
출력
5

예제 2

입력
4 0 1 0 1
4 1 0 0 1
출력
9

예제 3

입력
5 0 1 0 0 1
4 0 0 0 1
출력
13
코드를 제출하려면 로그인하세요.