MinhNGUYEN2k4

Untitled

Dec 4th, 2021
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define TASK ""
  3. #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
  4. #define READFILE freopen(TASK".INP","r",stdin)
  5. #define WRITEFILE freopen(TASK".OUT","w",stdout)
  6. #define For(i,a,b) for(int i=a;i<=b;i++)
  7. #define Rep(i,a,b) for(int i=a;i>=b;i--)
  8. #define pb push_back
  9. #define popb pop_back
  10. #define pf push_front
  11. #define popf pop_front
  12. #define ENDL '\n'
  13. #define debug(x) cout<<#x<<" = "<<x<<ENDL
  14. #define fi first
  15. #define se second
  16. #define ever (;true;)
  17. #define all(x) x.begin(),x.end()
  18. #define sz(a) ((int)(a).size())
  19. #define ms(a,x) memset(a,x,sizeof(a))
  20. #define int long long
  21.  
  22. using namespace std;
  23. typedef vector <int> vi;
  24. typedef pair <int,int> ii;
  25. typedef vector <ii> vpi;
  26. typedef pair <int,ii> iii;
  27. const int N = 100010;
  28. const int oo=0x3f;
  29. const int mod=1e9+7;
  30. const int dx[]={0,1,0,-1,0};
  31. const int base=311;
  32. const double EP=1e-9;
  33. int t,n,a[N];
  34. void sol(){
  35.     cin >> n;
  36.     ms(a,0);
  37.     For(i,1,3*n) cin >> a[i];
  38.     sort(a+1,a+1+3*n);
  39.     vi c;
  40.     vi b;
  41.     Rep(i,n*3,n+1){
  42.         b.pb(a[i]);
  43.         i--;
  44.         c.pb(a[i]);
  45.     }
  46.     int ans=0;
  47.     For(i,1,n){
  48.         ans+=(b[i-1]-a[i])*c[i-1];
  49.     }
  50.     cout << ans;
  51. }
  52. void init(){
  53.   FAST;
  54.   if (fopen(TASK".INP","r")){
  55.     READFILE;
  56.     WRITEFILE;
  57.   }
  58.   cin >> t;
  59. }
  60. signed main()
  61. {
  62.   init();
  63.   while (t--) sol();
  64.   return 0;
  65. }
RAW Paste Data