| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 0.5 초 | 2048 MB | 403 | 216 | 155 | 50.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$.
6 1 2 3 4 5 6 6 2 3 5 4 1
36
5 50 40 3 2 1 1 2 3 100 200
396
ICPC > Regionals > Asia Pacific > Korea > Asia Regional - Seoul 2023 H번
Camp > Petrozavodsk Programming Camp > Winter 2024 > Day 6: K-ontest I번