Logo
(追記) (追記ここまで)

19086번 - Leave Out All The Rest 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB23121152.381%

문제

You are given two integer arrays: an array $a$ of length $n$ and an array $b$ of length $m$. All integers in both arrays are pairwise distinct.

An interleaving of the two arrays is an array $c$ of size $n + m$ such that arrays $a$ and $b$ are its disjoint subsequences. Formally, there exist indices $i_1 < i_2 < \ldots < i_n$ such that $c_{i_1} = a_1,ドル $c_{i_2} = a_2,ドル $\ldots,ドル $c_{i_n} = a_n,ドル and indices $j_1 < j_2 < \ldots < j_m$ such that $c_{j_1} = b_1,ドル $c_{j_2} = b_2,ドル $\ldots,ドル $c_{j_m} = b_m$. For these indices, $i_x \neq j_y$ for all $x = 1, 2, \ldots, n$ and all $y = 1, 2, \ldots, m$.

It is clear that there are usually many ways to interleave arrays $a$ and $b$. Find such a way that maximizes the length of the longest increasing subsequence of $c$.

입력

The first line of input contains integer $n$ (1ドル \le n \le 5 \cdot 10^5$) --- the length of array $a$.

The second line contains $n$ integers $a_i$ (1ドル \le a_i \le 10^9$).

The third line of input contains integer $m$ (1ドル \le m \le 5 \cdot 10^5$) --- the length of array $b$.

The fourth line contains $m$ integers $b_j$ (1ドル \le b_j \le 10^9$).

It is guaranteed that the numbers in both arrays are pairwise distinct: $a_i \neq a_j$ for $i \neq j,ドル $b_i \neq b_j$ for $i \neq j$ and $a_i \neq b_j$ for all valid $i$ and $j$.

출력

Output one integer: the maximum length of the longest increasing subsequence in an interleaving of $a$ and $b$.

제한

예제 입력 1

2
1 7
3
6 10 11

예제 출력 1

5

예제 입력 2

3
7 1 5
3
9 8 6

예제 출력 2

3

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2017 > Day 5: Moscow IPT Contest J번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /