QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100

#8370. T3

統計

Alice and Bob are playing a game.

There is an $n \times m$ chessboard, where the cell at row $x$ and column $y$ is denoted as $(x,y)$.

Initially, a rook is placed at $(1,1)$. Alice and Bob take turns moving the rook, with Alice going first. In each turn, a player has two choices:

  1. Move the rook to any other cell in the same row or the same column. Specifically, if the rook is currently at $(x,y)$, it can be moved to $(c,y)$ where $1 \leq c \leq n$ and $c \neq x$, or to $(x,d)$ where $1 \leq d \leq m$ and $d \neq y$.
  2. End the game.

Alice and Bob realize that this game might never end, so they stipulate that at any point in time, the number of times any cell has been visited by the rook must be strictly less than $10^9$. Note that the starting cell $(1,1)$ is considered to have been visited once at the beginning.

Moving the piece is boring, so they provide two sequences $a$ and $b$ of lengths $n$ and $m$, respectively. When the game ends, if the rook is at $(x,y)$, the score of the game is $a_x + b_y$. Alice wants to minimize the score, while Bob wants to maximize it. You need to determine the score of the game assuming both players play optimally.

Input

The first line contains two integers $n$ and $m$, representing the size of the chessboard.

The second line contains $n$ integers $a_i$, representing the sequence $a$.

The third line contains $m$ integers $b_i$, representing the sequence $b$.

Output

Output a single integer representing the result.

Examples

Input 1

2 1
3 2
2

Output 1

4

Input 2

6 7
4 5 6 1 2 3
5 2 1 3 4 6 7

Output 2

7

Note

In Example 1, if both players choose to move, the target is uniquely determined. However, Bob realizes that on his $10^9-1$-th turn, moving the rook would cause the number of visits to cell $(1,1)$ to reach $10^9$, which is not a legal move. Therefore, Bob must choose to end the game during one of his turns, resulting in a score of $a_2 + b_1 = 4$.

In Example 2, the decision tree is of the order $5^{10^9}$, which is too large to illustrate here.

Constraints

For all data, $1 \leq n, m \leq 2 \times 10^5$, $1 \leq a_i, b_i \leq 10^8$.

Subtask 1 (14 points): $n, m \leq 4$.

Subtask 2 (11 points): $b_i = 1$.

Subtask 3 (15 points): $n, m \leq 10$.

Subtask 4 (16 points): $n, m \leq 10^3$.

Subtask 5 (19 points): $n, m \leq 5 \times 10^4$.

Subtask 6 (25 points): No additional constraints.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.