Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Observation: There is no avoiding using the largest value in both series (8) The only question that remains is: Which value in the other series should we pair 8 with ? Options: Remainding problem ----------------------------------------- (8,1) ---> S1' = 3 5 7 S2' = 2 4 6 (8,3) ---> S1' = 1 5 7 S2' = 2 4 6 (8,5) ---> S1' = 1 3 7 S2' = 2 4 6 (8,7) ---> S1' = 1 3 5 S2' = 2 4 6

Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Options: Remainding problem ----------------------------------------- (8,1) ---> S1' = 3 5 7 S2' = 2 4 6 (8,3) ---> S1' = 1 5 7 S2' = 2 4 6 (8,5) ---> S1' = 1 3 7 S2' = 2 4 6 (8,7) ---> S1' = 1 3 5 S2' = 2 4 6 Therefore: (the smallest of these 4 values is the answer) min(S1,S2) = speed(8,1) + min( (3 5 7), (2 4 6) ) or: min(S1,S2) = speed(8,3) + min( (1 5 7), (2 4 6) ) or: min(S1,S2) = speed(8,5) + min( (1 3 7), (2 4 6) ) or: min(S1,S2) = speed(8,7) + min( (1 3 5), (2 4 6) )

Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Options: Remainding problem ----------------------------------------- (8,1) ---> S1' = 3 5 7 S2' = 2 4 6 (8,3) ---> S1' = 1 5 7 S2' = 2 4 6 (8,5) ---> S1' = 1 3 7 S2' = 2 4 6 (8,7) ---> S1' = 1 3 5 S2' = 2 4 6 Therefore: (the smallest of these 4 values is the answer) min(S1,S2) = 8 + min( (3 5 7), (2 4 6) ) or: min(S1,S2) = 8 + min( (1 5 7), (2 4 6) ) or: min(S1,S2) = 8 + min( (1 3 7), (2 4 6) ) or: min(S1,S2) = 8 + min( (1 3 5), (2 4 6) )

Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Suppose you have 2 series S1' and S1'' that differs in 1 number: S1' = 1 3 5 S2' = 2 4 6 S1'' = x 3 5 and x > 1 then: min(S1', S2') <= min(S1'', S2') because if everything being equal, and x > 1, when you use x to compute the minimum, the minimum computed will be at least equal to the minimum computed when using 1

Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Previously: (the smallest of these 4 values is the answer) min(S1,S2) = speed(8,1)(=8) + min( (3 5 7), (2 4 6) ) or: min(S1,S2) = speed(8,3)(=8) + min( (1 5 7), (2 4 6) ) or: min(S1,S2) = speed(8,5)(=8) + min( (1 3 7), (2 4 6) ) or: min(S1,S2) = speed(8,7)(=8) + min( (1 3 5), (2 4 6) ) We have that: min( (1 3 5), (2 4 6) ) ≤ min( (1 3 7), (2 4 6) ) min( (1 3 5), (2 4 6) ) ≤ min( (1 5 7), (2 4 6) ) min( (1 3 5), (2 4 6) ) ≤ min( (3 5 7), (2 4 6) ) Therefore: the pairing (8,7) gives us the minimum

Analysis   how to find the minimum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     min(S1, S2) = min total speed computed with S1 and S2


Furthermore: The remaining problem: S1' = (1 3 5) S2' = (2 4 6) is identical in nature as the original problem. Therefore: Pair the largest numbers in each series with each other will result in the total mimimum

Analysis   how to find the maximum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     max(S1, S2) = max total speed computed with S1 and S2


Observation: There is no avoiding using the largest value in both series (8) The only question that remains is: Which value in the other series should we pair 8 with ? Options: Remainding problem ----------------------------------------- (8,1) ---> S1' = 3 5 7 S2' = 2 4 6 (8,3) ---> S1' = 1 5 7 S2' = 2 4 6 (8,5) ---> S1' = 1 3 7 S2' = 2 4 6 (8,7) ---> S1' = 1 3 5 S2' = 2 4 6

Analysis   how to find the maximum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     max(S1, S2) = max total speed computed with S1 and S2


Options: Remainding problem ----------------------------------------- (8,1) ---> S1' = 3 5 7 S2' = 2 4 6 (8,3) ---> S1' = 1 5 7 S2' = 2 4 6 (8,5) ---> S1' = 1 3 7 S2' = 2 4 6 (8,7) ---> S1' = 1 3 5 S2' = 2 4 6 Therefore: (the largest of these 4 values is the answer) max(S1,S2) = speed(8,1) + max( (3 5 7), (2 4 6) ) or: max(S1,S2) = speed(8,3) + max( (1 5 7), (2 4 6) ) or: max(S1,S2) = speed(8,5) + max( (1 3 7), (2 4 6) ) or: max(S1,S2) = speed(8,7) + max( (1 3 5), (2 4 6) )

Analysis   how to find the maximum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     max(S1, S2) = max total speed computed with S1 and S2


Suppose you have 2 series S1' and S1'' that differs in 1 number: S1' = 3 5 7 S2' = 2 4 6 S1'' = x 5 7 and x > 3 then: max(S1'', S2') >= max(S1', S2') because if everything being equal, and x > 3, when you use x to compute the maximum, the maximum computed will be at least equal to the maximum computed when using 3

Analysis   how to find the maximum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     max(S1, S2) = max total speed computed with S1 and S2


Previously: (the largest of these 4 values is the answer) max(S1,S2) = speed(8,1) + max( (3 5 7), (2 4 6) ) or: max(S1,S2) = speed(8,3) + max( (1 5 7), (2 4 6) ) or: max(S1,S2) = speed(8,5) + max( (1 3 7), (2 4 6) ) or: max(S1,S2) = speed(8,7) + max( (1 3 5), (2 4 6) ) We have that: max( (3 5 7), (2 4 6) ) ≥ max( (1 3 5), (2 4 6) ) max( (3 5 7), (2 4 6) ) ≥ max( (1 3 7), (2 4 6) ) max( (3 5 7), (2 4 6) ) ≥ max( (1 5 7), (2 4 6) ) Therefore: the pairing (8,1) gives us the maximum

Analysis   how to find the maximum total speed

 Suppose:

     S1 = 1 3 5 7   (some series of increasing speeds)
     S2 = 2 4 6 8   (another series of increasing speeds)

     max(S1, S2) = max total speed computed with S1 and S2


Furthermore: The remaining problem: S1' = (3 5 7) S2' = (2 4 6) is identical in nature as the original problem. Therefore: Pair the largest number in a series with the smallest number in the other series will result in the total maximum

Solution in C++
int main()
{
   int type;
   int N;
   int speed1[100], speed2[100];

   cin >> type;
   cin >> N;

   for ( int i = 0; i < N ; i++ )
      cin >> speed1[i];

   for ( int i = 0; i < N ; i++ )
      cin >> speed2[i];

   /* ---------------------------------------
      Sort the speeds
      --------------------------------------- */
   sort( speed1, speed1+N );
   sort( speed2, speed2+N );

   for ( int i = 0; i < N ; i++ )
      cout << speed1[i] << ",";
   cout << endl;

   for ( int i = 0; i < N ; i++ )
      cout << speed2[i] << ",";
   cout << endl;

   int sumSpeed = 0;

   // To get the lowest speed possible, pair the fastest people together
   for ( int i = 0; i < N; i++)
      sumSpeed += max( speed1[i], speed2[i] ); // Pairing: 1<->1 ... N<->N
   cout << "min speed = " << sumSpeed << endl;

   // To get the highest speed possible, pair the fastest in speed1 with
   // slowest in speed2
   sumSpeed = 0;
   for ( int i = 0; i < N; i++)
       sumSpeed += max( speed1[i], speed2[N-1-i] ); // Pairing: 1<->N ... N<->1
   cout << "max speed = " << sumSpeed << endl;