Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define TASK ""
- #define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- #define READFILE freopen(TASK".INP","r",stdin)
- #define WRITEFILE freopen(TASK".OUT","w",stdout)
- #define For(i,a,b) for(int i=a;i<=b;i++)
- #define Rep(i,a,b) for(int i=a;i>=b;i--)
- #define pb push_back
- #define popb pop_back
- #define pf push_front
- #define popf pop_front
- #define ENDL '\n'
- #define debug(x) cout<<#x<<" = "<<x<<ENDL
- #define fi first
- #define se second
- #define ever (;true;)
- #define all(x) x.begin(),x.end()
- #define sz(a) ((int)(a).size())
- #define ms(a,x) memset(a,x,sizeof(a))
- #define int long long
- using namespace std;
- typedef vector <int> vi;
- typedef pair <int,int> ii;
- typedef vector <ii> vpi;
- typedef pair <int,ii> iii;
- const int N = 100010;
- const int oo=0x3f;
- const int mod=1e9+7;
- const int dx[]={0,1,0,-1,0};
- const int base=311;
- const double EP=1e-9;
- int t,n,a[N];
- void sol(){
- cin >> n;
- ms(a,0);
- For(i,1,3*n) cin >> a[i];
- sort(a+1,a+1+3*n);
- vi c;
- vi b;
- Rep(i,n*3,n+1){
- b.pb(a[i]);
- i--;
- c.pb(a[i]);
- }
- int ans=0;
- For(i,1,n){
- ans+=(b[i-1]-a[i])*c[i-1];
- }
- cout << ans;
- }
- void init(){
- FAST;
- if (fopen(TASK".INP","r")){
- READFILE;
- WRITEFILE;
- }
- cin >> t;
- }
- signed main()
- {
- init();
- while (t--) sol();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement