Advertisement
rayated

Kayaking 2 codeforces

Jun 3rd, 2021
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #pragma GCC optimize("Ofast")
  2. #pragma GCC target("avx,avx2,fma")
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. int main()
  6. {
  7.     ios_base::sync_with_stdio(false);cin.tie(NULL);
  8.     int n,a[200],sum=0,mx=0x3f3f3f3f;cin>>n;
  9.     for(int i=0;i<(2*n);i++){cin>>a[i];}
  10.     sort(a,a+n*2);
  11.     for(int i=0;i<(2*n-1);i++)
  12.     {
  13.         for(int j=i+1;j<2*n;j++)
  14.         {
  15.             sum=0;
  16.             for(int k=0;k<(2*n-1);)
  17.             {
  18.                 if (k==i || k==j)k++;
  19.                 else if ((k+1)!=i || (k+1)!=j){sum+=(a[k+1]-a[k]);k+=2;}
  20.                 else if ((k+2)==j){sum+=(a[k+3]-a[k]);k+=4;}
  21.                 else if ((k+1)==i){sum+=(a[k+2]-a[k]);k+=3;}
  22.             }
  23.             mx=min(mx,sum);
  24.         }
  25.     }
  26.     cout<<mx<<endl;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement