#6303. [ICPC 2023 Seoul R] M. S. I. S.

[ICPC 2023 Seoul R] M. S. I. S.

[ICPC 2023 Seoul R] M. S. I. S.

题目描述

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*.

Once we permute the columns of MM, MSIS can change. For example, if we permute the columns of the above matrix M=[c1,c2,c3,c4,c5,c6]M=[c_1,c_2,c_3,c_4,c_5,c_6] to M=[c2,c3,c4,c5,c6,c1]M=[c_2,c_3,c_4,c_5,c_6,c_1] as the figure below, MSIS becomes 3636.

Given a 2×n2\times n matrix MM, write a program to output the maximum of MSIS among all possible permutations of the columns of MM.

输入格式

Your program is to read from standard input. The input starts with a line containing an integer, $n$ ($1 \le n\le 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

提示

(暂无提示) 标签: P14092|动态规划 DP|树状数组|2023|ICPC|首尔

来源

P14092|[ICPC 2023 Seoul R] M. S. I. S.