Type: Default 2000ms 256MiB

Max Ai+Bj

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

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

SDNU_ACM_ICPC_2024_WEEKLY_PRACTICE_1st

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2024-10-27 18:30
End at
2024-10-27 21:30
Duration
3 hour(s)
Host
Partic.
39