Friday, April 24, 2015

UVa - 10041 - Vito's Family

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int t, n, m, mn, x, ans;
    vector <int> street;
    cin >> t;
    while(t--){
        cin >> n, x = n, mn = 2111111111;
        while(n--)cin >> m, street.push_back(m);
        for(int i = 0; i < x; i++){
             ans = 0;
            for(int j = 0; j < x; j++)ans += abs(street[i] - street[j]);
            if(ans < mn)mn = ans;
        }
        cout << mn << endl;
        street.clear();
    }
    return 0;
}

No comments:

Post a Comment