Advertisement
tepyotin2

Untitled

Oct 8th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int skill[13];
  6. int cowt[13];
  7. int n = 12;
  8. long long ans = INT32_MAX;
  9.  
  10. void allocate(int pos, int team1, int team2, int team3, int team4){
  11.     if(team1 > 3 || team2 > 3 || team3 > 3 || team4 > 3){
  12.         cout << "team: "<< team1 << ", " << team2 << ", " << team3 << ", " << team4 << endl;
  13.         return;
  14.     }
  15.     for(int i=1; i<=4; i++){
  16.         cowt[pos] = i;
  17.         // if(i ==1){
  18.         //     team1++;
  19.         // }else if(i == 2){
  20.         //     team2++;
  21.         // } else if(i == 3){
  22.         //     team3++;
  23.         // }else{
  24.         //     team4++;
  25.         // }
  26.         if(pos<n){
  27.             allocate(pos+1, team1+(i==1), team2+(i==2), team3+(i==3), team4+(i==4));
  28.         }else{
  29.             //allocated to every single value
  30.             // string coc = "";
  31.             // int team1 = 0, team2 = 0, team3 = 0, team4 = 0;
  32.             // int x1 = 0, x2 = 0, x3 = 0, x4 = 0;
  33.             // int n1, n2, n3, n4;
  34.             // n1 = n2 = n3 = n4 = INT_MAX;
  35.             long long sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
  36.             for(int i=1; i<=n; i++){
  37.                 if(cowt[i] == 1){
  38.                     // team1++;
  39.                     sum1 += skill[i];
  40.                     // x1 = max(x1, skill[i]);
  41.                     // n1 = min(n1, skill[i]);
  42.                 }else if(cowt[i] == 2){
  43.                     // team2++;
  44.                     sum2 += skill[i];
  45.                     // x2 = max(x2, skill[i]);
  46.                     // n2 = min(n2, skill[i]);
  47.                 }else if(cowt[i] == 3){
  48.                     // team3++;
  49.                     sum3 += skill[i];
  50.                     // x3 = max(x3, skill[i]);
  51.                     // n3 = min(n3, skill[i]);
  52.                 }else{
  53.                     // team4++;
  54.                     sum4 += skill[i];
  55.                     // x4 = max(x4, skill[i]);
  56.                     // n4 = min(n4, skill[i]);
  57.                 }
  58.                 // cout << coc << cowt[i];
  59.                 // coc = ", ";
  60.             }
  61.             // cout << ", team1: " << team1 << ", team2: " << team2 << ", team3: " << team3 << ", team4: " << team4 << '\n';
  62.             if(team1 == 3 && team2 == 3 && team3 == 3 && team4 == 3){
  63.              
  64.                 long long diff = max(sum1, max(sum2, max(sum3, sum4))) - min(sum1, min(sum2, min(sum3, sum4)));
  65.                 ans = min(diff, ans);
  66.             }
  67.         }
  68.     }
  69. }
  70.  
  71. int main(){
  72.     ios_base::sync_with_stdio(0), cin.tie(0);
  73.     freopen("bteams.in", "r", stdin);
  74.     // freopen("bteams.out", "w", stdout);
  75.     for(int i=1; i<=n; i++){
  76.         cin >> skill[i];
  77.     }
  78.     // for(int i=1; i<=12; i++){
  79.     //     cout << "i: " << i << ", skill[i]: " << skill[i] << '\n';
  80.     // }
  81.     allocate(1, 0, 0, 0, 0);
  82.     cout << ans << '\n';
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement