1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import java.util.Arrays; import java.util.Scanner; /** * UVA10041 */ public class UVA10041 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); for (int i = 0; i < times; i++) { int count = sc.nextInt(); int[] num = new int[count]; for (int j = 0; j < num.length; j++) num[j] = sc.nextInt(); Arrays.sort(num); int sum = 0; for (int j = 0; j < num.length; j++) sum += Math.abs(num[j] - num[num.length / 2]); System.out.println(sum); } sc.close(); } } |