-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Sasha_and_Array_Coloring.cpp
77 lines (70 loc) · 1.61 KB
/
A_Sasha_and_Array_Coloring.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// DATE: 28-06-2023
// TIME: 06-36-31
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; i++)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dep(i, b, a) for (int i = b; i >= a; i--)
#define print(x) cout << x << "\n"
#define vin(v) \
for (auto &x : v) \
cin >> x
// #define vin() for(ll i=0;i<n;i++) cin>>v[i]
#define vout(v) \
for (auto x : v) \
cout << x << " "; \
cout << endl
// #define vout() for(ll i=0;i<n;i++) cout<<v[i]<<" "
// #define vout(a,b,v) for(int i=a;i<b;i++){cout<<v[i]<<" ";}cout<<"\n";
#define vect(type1, name) vector<type1> name
#define vectp(type1, type2, name) vector<pair<type1, type2>> name
#define set(type, name) set<type> name
#define mpp(type1, type2, name) map<type1, type2> name
const int M = 1e9 + 7;
const int N = 1e5 + 7;
#define Pi 3.1415926535897932384626
// extern int x;
void solve()
{
int n;
cin >> n;
vector<int> v(n);
for (ll i = 0; i < n; i++)
cin >> v[i];
sort(all(v));
int sum = 0;
if (n == 1)
{
cout << 0 << endl;
return;
}
for (int i = 0; i < n / 2; i++)
{
if (n % 2 == 0)
{
sum = sum + (v[n - i - 1] - v[i]);
}
else
{
sum = sum + (v[n - i - 1] - v[i]);
}
}
cout << sum << endl;
return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(NULL);
ll t; //= 1;
cin >> t;
while (t--)
{
solve();
}
return 0;
}