TORONTO KIDS COMPUTER CLUB | PMCA Friday 19:00 Python Homework 21.03.12.
19168

# PMCA Friday 19:00 Python Homework 21.03.12.

## 15 Mar PMCA Friday 19:00 Python Homework 21.03.12.

Question:
Since time immemorial, the citizens of Mongna and Negland 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 N citizens from each country. They must be assigned to pairs so that each pair contains one person from Mongna and one person from Negland .

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). The total speed is the sum of the N 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 Specification
The first line will contain the type of question you are to solve, which is either 1 or 2.

The second line contains N (1N100).

The third line contains N space-separated integers: the speeds of the citizens of Mongna .

The fourth line contains N space-separated integers: the speeds of the citizens of Negland .

Each person’s speed will be an integer between 1 and 1000000.

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

Sample Input 1135 1 46 2 4Output for Sample Input 112Explanation for Output for Sample Input 1There is a unique optimal solution:Pair the citizen from Mongna with speed 5 and the citizen from Negland with speed 6.Pair the citizen from Mongna with speed 1 and the citizen from Negland with speed 2.Pair the citizen from Mongna with speed 4 and the citizen from Negland with speed 4.Sample Input 2235 1 46 2 4Output for Sample Input 215Explanation for Output for Sample Input 2There are multiple possible optimal solutions. Here is one optimal solution:Pair the citizen from Mongna with speed 5 and the citizen from Negland with speed 2.Pair the citizen from Mongna with speed 1 and the citizen from Negland with speed 6.Pair the citizen from Mongna with speed 4 and the citizen from Negland with speed 4.Sample Input 325202 177 189 589 10217 78 1 496 540Output for Sample Input 32016Explanation for Output for Sample Input 3There are multiple possible optimal solutions. Here is one optimal solution:Pair the citizen from Mongna with speed 202 and the citizen from Negland with speed 1.Pair the citizen from Mongna with speed 177 and the citizen from Negland with speed 540.Pair the citizen from Mongna with speed 189 and the citizen from Negland with speed 17.Pair the citizen from Mongna with speed 589 and the citizen from Negland with speed 78.Pair the citizen from Mongna with speed 102 and the citizen from Negland with speed 496.This sum yields 202+540+189+589+496=2016.