#P15522. [CCC 2016 J5/S2] Tandem Bicycle

    ID: 15363 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>贪心2016排序CCC(加拿大)分类讨论STL

[CCC 2016 J5/S2] Tandem Bicycle

Description

Since time immemorial, the citizens of Dmojistan and Pegland have been at war. Now, they have finally signed a truce. They have decided to participate in a tandem bicycle ride to celebrate the truce. There are NN citizens from each country. They must be assigned to pairs so that each pair contains one person from Dmojistan and one person from Pegland.

Each citizen has a cycling speed. In a pair, the fastest person will always operate the tandem bicycle while the slower person simply enjoys the ride. In other words, if the members of a pair have speeds aa and bb, then the bike speed of the pair is max(a,b)\max(a, b). The total speed is the sum of the NN individual bike speeds.

For this problem, in each test case, you will be asked to answer one of two questions:

  • Question 1: what is the minimum total speed, out of all possible assignments into pairs?
  • Question 2: what is the maximum total speed, out of all possible assignments into pairs?

Input Format

The first line will contain the type of question you are to solve, which is either 11 or 22.

The second line contains NN (1N1001 \leq N \leq 100).

The third line contains NN space-separated integers: the speeds of the citizens of Dmojistan.

The fourth line contains NN space-separated integers: the speeds of the citizens of Pegland.

Each person's speed will be an integer between 11 and 1 000 0001\ 000\ 000.

For 88 of the 1515 available marks, questions of type 11 will be asked. For 77 of the 1515 available marks, questions of type 22 will be asked.

Output Format

Output the maximum or minimum total speed that answers the question asked.

1
3
5 1 4
6 2 4
12
2
3
5 1 4
6 2 4
15
2
5
202 177 189 589 102
17 78 1 496 540
2016

Hint

Explanation for Output for Sample Input 1

There is a unique optimal solution:

  • Pair the citizen from Dmojistan with speed 55 and the citizen from Pegland with speed 66.
  • Pair the citizen from Dmojistan with speed 11 and the citizen from Pegland with speed 22.
  • Pair the citizen from Dmojistan with speed 44 and the citizen from Pegland with speed 44.

Explanation for Output for Sample Input 2

There are multiple possible optimal solutions. Here is one optimal solution:

  • Pair the citizen from Dmojistan with speed 55 and the citizen from Pegland with speed 22.
  • Pair the citizen from Dmojistan with speed 11 and the citizen from Pegland with speed 66.
  • Pair the citizen from Dmojistan with speed 44 and the citizen from Pegland with speed 44.

Explanation for Output for Sample Input 3

There are multiple possible optimal solutions. Here is one optimal solution:

  • Pair the citizen from Dmojistan with speed 202202 and the citizen from Pegland with speed 11.
  • Pair the citizen from Dmojistan with speed 177177 and the citizen from Pegland with speed 540540.
  • Pair the citizen from Dmojistan with speed 189189 and the citizen from Pegland with speed 1717.
  • Pair the citizen from Dmojistan with speed 589589 and the citizen from Pegland with speed 7878.
  • Pair the citizen from Dmojistan with speed 102102 and the citizen from Pegland with speed 496496.

This sum yields 202+540+189+589+496=2016202 + 540 + 189 + 589 + 496 = 2016.