I'm doing a code-challenge problem:
Captain Kaban: National Treasure is a popular football simulation game which can be played on most smartphones. In this game, you put up a team of 11 players and then compete in either story mode or multi-player mode. As you might already know, a football match is played by 11 players, which consists of one goalkeeper and ten outfield players.
Each outfield player's capability is measured with scores in 3 areas: Attack (dribble, shoot, pass), Defense (tackle, block, intercept), and Physical (speed, power, technique). For example, a player with A:4103 D:2837 P:3410 is a typical attacker player (forward position) as his Attack (4103) is higher than his Defense (2837) and Physical (3410). On the other hand, a player with A:1546, D:5209, P:2708 is a typical defensive player as his Defense is much higher than his Attack and Physical. A goalkeeper has a different measurement (Saving and Physical), but it's not our concern in this problem.
A team strength is simply the sum of all the main outfield player's capability-scores. Note that the team strength score does not consider the team's balance, e.g., a team of 10 players where each player has A:8000, D:1000, P:1000 is stronger than a team where each player has A:3000, D:3000, P:3000; the first team's team strength is 100,000 (10 * (8000 + 1000 + 1000)) while the second one is 90,000 (10 * (3000 + 3000 + 3000)).
Let say you are given a team with ten main outfield players and N reserve players. If you are allowed to substitute at most 1 main outfield player (with a reserve player), what is the maximum team strength you can obtain?
Input
Input begins with an integer: T
(1 ≤ T
≤ 20) denoting the number of cases.
Each case contains the following input block: Each case begins with an integer: N
(1 ≤ N
≤ 10) denoting the number of reserve players. The next 10 lines each contains three integers: Ai
Di
Pi
(100 ≤ Ai
, Di
, Pi
≤ 20,000) representing the Attack, Defense, and Physical score for the ith main player. The next N lines each contains three integers: Aj
Dj
Pj
(100 ≤ Aj
, Dj
, Pj
≤ 20,000) representing the Attack, Defense, and Physical score for the jth reserve player.
Output
For each case, output in a line "Case #X: Y" where X is the case number (starts from 1) and Y is the output for the respective case.
#include <iostream>
using namespace std;
int main () {
const int totalOriginalPlayer {10};
int testCases {};
cin >> testCases;
for (int i = 1; i <= testCases; i++) {
int reserve {}, total {}, lowest {500000}, highest {};
int attack {}, defense {}, physical {};
cin >> reserve;
int reservePlayers [reserve];
int powerReservePlayers [reserve];
int powerOriginalPlayers [totalOriginalPlayer];
// Get power of all original players, calculate sum and find the minimum
for (int i = 0; i < totalOriginalPlayer; i++) {
cin >> attack >> defense >> physical;
powerOriginalPlayers[i] = attack + defense + physical;
total += powerOriginalPlayers[i];
if (powerOriginalPlayers[i] < lowest) {
lowest = powerOriginalPlayers[i];
}
}
// Get power of all reserve players and find the maximum power
for (int j = 0; j < reserve; j++) {
cin >> attack >> defense >> physical;
powerReservePlayers[j] = attack + defense + physical;
if (powerReservePlayers[j] > highest) {
highest = powerReservePlayers[j];
}
}
// Subtract total with lowest and add highest
if (lowest < highest) {
total = total - lowest + highest;
} else if (lowest >= highest) {
total = total;
}
// Print out total
cout << "Case #" << i << ": "<< total << endl;
}
}