forked from hughbzhang/Competitive_Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bteams.cpp
36 lines (29 loc) · 761 Bytes
/
bteams.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cstdio>
#include <algorithm>
#define LARGE (1e7)
using namespace std;
int arr[12];
int order[] = {0,0,0,1,1,1,2,2,2,3,3,3};
int ans = LARGE;
int score[4];
int main(){
freopen("bteams.in","r",stdin);
freopen("bteams.out","w",stdout);
for(int x = 0;x<12;x++){
scanf("%d",&arr[x]);
}
sort(arr,arr+12);
do{
for(int x = 0;x<4;x++) score[x] = 0;
for(int x = 0;x<12;x++) score[order[x]]+=arr[x];
int min = LARGE;
int max = 0;
for(int x = 0;x<4;x++){
if(score[x]<min) min = score[x];
if(score[x]>max) max = score[x];
}
if(max-min<ans) ans = max-min;
}while(next_permutation(order,order+12));
printf("%d\n",ans);
return 0;
}