M. S. I. S.
Time limit0.5sMemory limit2048 MB
Given a 2 by n matrix, reorder its columns to maximize the sum of the best increasing subsequence sums in the two rows.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Graph, Sorting
- Solved
- No attempts yet
Problem
We are given a matrix of positive integers. No row of contains a duplicate number. For the -th row (), let be the maximum sum of an increasing subsequence of . For example, in the matrix below, is and is .
We call the maximum sum of increasing subsequences (MSIS). Permuting the columns of can change the MSIS. In the matrix below, the columns are rearranged to , and the MSIS becomes 36.
Given , find the maximum MSIS over all permutations of its columns.
Input
The first line contains an integer (), the number of columns of . The next two lines each contain integers, the entries of row 1 and row 2. All integers are between 1 and 50000, and no row contains a duplicate number.
Output
Print one line containing the maximum MSIS over all permutations of the columns of .