#abc373c. C - Max Ai+Bj

C - Max Ai+Bj

Score : 250250 points

问题陈述

给定两个整数序列 AABB,每个序列的长度为 NN。选择整数 i,ji, j (1i,jN)(1 \leq i, j \leq N) 以最大化 Ai+BjA_i + B_j 的值。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given two integer sequences AA and BB, each of length NN. Choose integers i,ji, j (1i,jN)(1 \leq i, j \leq N) to maximize the value of Ai+BjA_i + B_j.

Constraints

  • 1N5×1051 \leq N \leq 5 \times 10^5
  • Ai109|A_i| \leq 10^9 (i=1,2,,N)(i=1,2,\dots,N)
  • Bj109|B_j| \leq 10^9 (j=1,2,,N)(j=1,2,\dots,N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

B1B_1 B2B_2 \dots BNB_N

Output

Print the maximum possible value of Ai+BjA_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)(i,j) = (1,1), (1,2), (2,1), (2,2), the values of Ai+BjA_i + B_j are 2,8,8,22, -8, 8, -2 respectively, and (i,j)=(2,1)(i,j) = (2,1) achieves the maximum value 88.

Sample Input 2

6
15 12 3 -13 -1 -19
7 17 -13 -10 18 4

Sample Output 2

33