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

30859번 - M. S. I. S. 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.5 초 2048 MB40321615550.000%

문제

We are given a 2ドル \times n$ matrix $M$ of positive integers, and each row of $M$ does not contain duplicate numbers. For $i$-th row $r_i$ of $M,ドル $i = 1, 2,ドル we find the maximum sum $s_i$ of increasing subsequence contained in $r_i$. For example, if $M$ is given as the figure below, $s_1$ is 1ドル + 2 + 3 + 4 + 5 + 6$ and $s_2$ is 2ドル + 3 + 5$. We call $s_1 + s_2$ the maximum sum of increasing subsequences, MSIS.

$$\begin{bmatrix} \color{red}{1} & \color{red}{2} & \color{red}{3} & \color{red}{4} & \color{red}{5} & \color{red}{6}\\ 6 & \color{red}{2} & \color{red}{3} & \color{red}{5} & 4 & 1 \end{bmatrix}$$

Once we permute the columns of $M,ドル MSIS can change. For example, if we permute the columns of the above matrix $M = [c_1,円 c_2,円 c_3,円 c_4,円 c_5,円 c_6]$ to $[c_2,円 c_3,円 c_4,円 c_5,円 c_6,円 c_1]$ as the figure below, MSIS becomes 36ドル$.

$$\begin{bmatrix} \color{red}{2} & \color{red}{3} & \color{red}{4} & \color{red}{5} & \color{red}{6} & 1 \\ \color{red}{2} & \color{red}{3} & \color{red}{5} & 4 & 1 & \color{red}{6} \end{bmatrix}$$

Given a 2ドル \times n$ matrix $M,ドル write a program to output the maximum of MSIS among all possible permutations of the columns of $M$.

입력

Your program is to read from standard input. The input starts with a line containing an integer, $n$ (1ドル ≤ n ≤ 10,000円$), where $n$ is the number of columns of the input matrix $M$. In the following two lines, the $i$-th line contains $n$ positive integers of the $i$-th row of $M,ドル for $i = 1, 2$. The integers given as input are between 1ドル$ and 50ドル,000円,ドル and each row does not contain duplicate numbers.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the maximum of MSIS among all possible permutations of columns of $M$.

제한

예제 입력 1

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

예제 출력 1

36

예제 입력 2

5
50 40 3 2 1
1 2 3 100 200

예제 출력 2

396

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Asia Regional - Seoul 2023 H번

Camp > Petrozavodsk Programming Camp > Winter 2024 > Day 6: K-ontest I번

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

출처

대학교 대회

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

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