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:
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:
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:
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:
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:
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:
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:
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:
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:
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:
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
|
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;
|