## CCC '16 S2 - Tandem Bicycle

View as PDF

Points: 5 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types
##### Canadian Computing Competition: 2016 Stage 1, Junior #5, Senior #2

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 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 and , then the bike speed of the pair is . The total speed is the sum of the 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 or .

The second line contains .

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

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

Each person's speed will be an integer between and .

For 8 of the 15 available marks, questions of type will be asked. For 7 of the 15 available marks, questions of type will be asked.

#### Output Specification

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

#### Sample Input 1

1
3
5 1 4
6 2 4

#### Output for Sample Input 1

12

#### Explanation for Output for Sample Input 1

There is a unique optimal solution:

• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .

#### Sample Input 2

2
3
5 1 4
6 2 4

#### Output for Sample Input 2

15

#### 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 and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .

#### Sample Input 3

2
5
202 177 189 589 102
17 78 1 496 540

#### Output for Sample Input 3

2016

#### 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 and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .
• Pair the citizen from Dmojistan with speed and the citizen from Pegland with speed .

This sum yields .

• MakanDey  commented on Feb. 14, 2019, 9:19 p.m. edited

For sample case one, shouldn't it be 10 instead of 12 if it wants the minimum?

• GeoHD  commented on Feb. 14, 2019, 10:14 p.m.

No, it should be 12. Look at the explanation. When you pair them up, you only take the sum of all the cyclist which cycles the fastest out of the pair.

• d  commented on Feb. 29, 2016, 10:55 p.m.

Check out the user profile of wcipeg.

• PiMachine  commented on Feb. 20, 2016, 10:26 p.m.

"DMOJ"istan and "PEG"land LOL XD

• yellowsn0w1004  commented on Feb. 20, 2016, 3:46 p.m.

So Tandem Bicycle is problem 5 on the junior exam and is supposed to be the hardest (according to order), but I found that it was significantly easier than problems 3 and 4.

Am I wrong thinking that the problems are in order of difficulty?

Anyone else find this weird?

• odaniel  commented on Feb. 20, 2016, 6:03 p.m. edited

It's a "big-data" question - designed to catch people with ultra-naive solutions. Note that the speeds can be as high as one million - if somebody tried to compare every single combination, it would take forever.