103732: [Atcoder]ABC373 C - Max Ai+Bj
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:6
Solved:0
Description
Score : $250$ points
Problem Statement
You are given two integer sequences $A$ and $B$, each of length $N$. Choose integers $i, j$ $(1 \leq i, j \leq N)$ to maximize the value of $A_i + B_j$.
Constraints
- $1 \leq N \leq 5 \times 10^5$
- $|A_i| \leq 10^9$ $(i=1,2,\dots,N)$
- $|B_j| \leq 10^9$ $(j=1,2,\dots,N)$
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$N$ $A_1$ $A_2$ $\dots$ $A_N$ $B_1$ $B_2$ $\dots$ $B_N$
Output
Print the maximum possible value of $A_i + B_j$.
Sample Input 1
2 -1 5 3 -7
Sample Output 1
8
For $(i,j) = (1,1), (1,2), (2,1), (2,2)$, the values of $A_i + B_j$ are $2, -8, 8, -2$ respectively, and $(i,j) = (2,1)$ achieves the maximum value $8$.
Sample Input 2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
Sample Output 2
33
Output
得分:250分
问题陈述
给你两个整数序列A和B,每个序列的长度为N。选择整数i, j(1 ≤ i, j ≤ N)以最大化A_i + B_j的值。
约束条件
- 1 ≤ N ≤ 5 × 10^5
- |A_i| ≤ 10^9(i=1,2,…,N)
- |B_j| ≤ 10^9(j=1,2,…,N)
- 所有输入值都是整数。
输入
输入从标准输入以下格式给出:
N A_1 A_2 … A_N B_1 B_2 … B_N
输出
打印A_i + B_j可能的最大值。
示例输入1
2 -1 5 3 -7
示例输出1
8
对于(i,j) = (1,1), (1,2), (2,1), (2,2),A_i + B_j的值分别为2, -8, 8, -2,并且(i,j) = (2,1)达到最大值8。
示例输入2
6 15 12 3 -13 -1 -19 7 17 -13 -10 18 4
示例输出2
33