initial commit
This commit is contained in:
parent
0482f2cd40
commit
3f3cc6ca7e
34
1843A Sasha and Array Coloring/1843A.cpp
Normal file
34
1843A Sasha and Array Coloring/1843A.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
using ll = long long;
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
vector<int> v;
|
||||
for(int i=0; i<n; ++i)
|
||||
{
|
||||
int x;
|
||||
cin>>x;
|
||||
v.push_back(x);
|
||||
}
|
||||
sort(v.begin(),v.end());
|
||||
int cost=0;
|
||||
for(int i=0, j=n-1; i<j; ++i, --j)
|
||||
{
|
||||
cost=cost+v[j]-v[i];
|
||||
}
|
||||
cout<<cost<<endl;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int TC = 1;
|
||||
cin >> TC;
|
||||
cin.ignore();
|
||||
while (TC--) solve();
|
||||
}
|
Loading…
Reference in New Issue
Block a user