Vito'sfamily

 avatar
user_6817964
c_cpp
a year ago
493 B
1
Indexable
Never
#include <iostream>
#include <algorithm>

using namespace std;

int n, r, s[500];


bool cmp(int a, int b){
    return a < b;
}

main(){
    cin >> n;
    for(int k = 0; k < n; k++){
        cin >> r;
        for (int i = 0; i < r; i++){
            cin >> s[i];
        }
        sort(s, s+r, cmp);
        int mid = s[r/2];
        int sum = 0;
        for (int i = 0; i < r; i++){
            sum += abs(s[i] - mid);
        }
        cout << sum << endl;
    }
}