An Easy Problem(水 金马五校赛-东华大学)
2017-07-19 10:35
267 查看
Problem O : An Easy Problem
From:DHUOJ, 2017060315
<a type="button" class="btn btn-default" href="/solution/submit.html?problemId=5298">Submit</a> (Out of Contest)
Time Limit: 2 s
Description
Zhu Ge is a very clever boy. One day, he discovered 2*n numbers. He wanted to divide them inton groups, each group contains 2 integers, and minimize the sum of the absolute value of the difference of the numbers in each group.The problem is too difficult to Zhu Ge, so he turned to you. He hopes you can calculate the minimum of the sum of absolute value of the difference among different division strategies.
Input
There are several test cases.For each test case, there is an integer n (n < 10,000) at the first line. The second line contains 2*n integers. The input ends up with EOF.
Output
For each test case, output the minimum of sum.Sample Input
3 10 3 4 5 1 6 5 64 5 63 63 23 63 54 64 3 54
Sample Output
7 42
Author: Kuang
#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> using namespace std; long long a[20002]; int main(){ int n; while(~scanf("%d",&n)){ for(int i=1;i<=2*n;i++){ scanf("%lld",&a[i]); } long long sum=0; sort(a+1,a+2*n+1); for(int i=1;i<=2*n;i+=2)sum=sum+abs((a[i+1]-a[i])); printf("%lld\n",sum); } return 0; }
相关文章推荐
- An Easy Problem?! POJ 2826 计算几何
- HDU:2055 An easy problem
- B - An easy problem
- An easy problem+数学推理
- HDU 5475 An easy problem 线段树
- An Easy Problem
- hdu 2601 An easy problem
- An easy DP problem HDOJ 1176
- HDOJ(HDU) 2123 An easy problem(简单题...)
- 杭电 ACM 2055 An easy problem
- *寒假水18——An easy problem(字母转换成数字)
- hdu-An Easy Problem
- 水题堆1.V An easy problem
- HDU2601,An easy problem
- POJ 2826 An Easy Problem?!
- UESTC - 1597 An easy problem C (线段树)
- hdoj 2055 An easy problem
- HDU 2061 An easy problem(水)
- POJ 2826 An Easy Problem?!(线段相交,比较角度大小)
- 杭电2055——An easy problem