Contrast Moe
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 0 Accepted Submission (s): 0
Problem description has 2N individuals, each with an Moe mi (1<=i<=2n).
They are required to be divided into n pairs, so that the sum of the contrast values is maximal.
The meaning of the contrast value is as follows: if x and Y are a pair, they contribute | mx-my| point contrast value. The first line of input is a number T, which indicates the number of test instances.
followed by the T-line, the first number of n per line, then the 2N individual's Moe mi.
1<=t<=10
1<=n<=1000
-1000<=mi<=1000
All input numbers are integers. Output for each set of instances, export the maximum value of the sum of the contrast values, one row per test instance.
Sample Input21 13 142 1-2 0 3
Sample Output16 Solution: Sort + END Add
#include <bits/stdc++.h>using namespacestd;intMain () {intT; CIN>>T; while(t--) { inta[10000]; intN; CIN>>N; for(intI=1; i<=2*n;i++) {cin>>A[i]; } intsum=0; Sort (a+1, A +1+2*N); for(intI=1; i<=n;i++) {sum+ = (ABS (a[i]-a[2*n-i+1])); } cout<<sum<<Endl; } return 0;}
Hangzhou Computer Program Design Competition (2016 ' 12)-Network synchronization 1007