Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define pb push_back
- using namespace std;
- int main(){
- int t , n , tmp;
- vector<int> p;
- cin >> t;
- while( t-- ){
- int min = 30000 , max = 0;
- p.clear();
- cin >> n;
- while( n-- ) {
- cin >> tmp;
- tmp < min ? min = tmp : min;
- tmp > max ? max = tmp : max;
- p.pb( tmp );
- }
- int ans = 7777777;
- for( int i = min ; i <= max ; i++ ){
- int sum = 0;
- for( int j = 0 ; j < p.size() ; j++ ) sum += abs( i - p[j] );
- if( sum > ans ) break;
- ans = sum;
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement