Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- using namespace std;
- int player_skill[12];
- int player_team[12];
- int team_count[4];
- int answer = -1;
- void recurse(int player) {
- if (player == 12) {
- int team_skill[4] = {0,0,0,0};
- for (int i = 0; i < 12; i++) {
- team_skill[player_team[i]] += player_skill[i];
- }
- int S = max(max(team_skill[0], team_skill[1]),
- max(team_skill[2], team_skill[3]));
- int s = min(min(team_skill[0], team_skill[1]),
- min(team_skill[2], team_skill[3]));
- if (answer == -1 || S - s < answer) {
- answer = S - s;
- }
- return;
- }
- for (int team = 0; team < 4; team++) {
- if (team_count[team] < 3) {
- player_team[player] = team;
- team_count[team]++;
- recurse(player+1);
- team_count[team]--;
- }
- }
- }
- int main() {
- freopen("bteams.in", "r", stdin);
- freopen("bteams.out", "w", stdout);
- for (int i = 0; i < 12; i++) {
- scanf("%d", &player_skill[i]);
- }
- recurse(0);
- printf("%d\n", answer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement