U E D R , A S I H C RSS

Vitos Family/Celfin

~cpp
#include <iostream>
#include <algorithm>
using namespace std;

int testcase, homeNum, i;
int sum;

int addressList[500];

int main()
{
	cin>>testcase;
	while(testcase--)
	{
		cin>>homeNum;
		for(i=0; i<homeNum; i++)
			cin >> addressList[i];
		sort(&addressList[0], &addressList[homeNum]);
		sum=0;
		for(i=0; i<homeNum; i++)
			sum+=abs(addressList[i]-addressList[(homeNum-1)/2]);
		cout << sum << endl;
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:22
Processing time 0.0089 sec