Problem O : An Easy Problem
From: DHUOJ, 2017060315
(Out of Contest)
题目意思就是给一个n,然后输入n*2个数,分成n个组将每组的差的绝对值加起来,让这个值最小,求出这个值。
就是按照大小顺序排序,然后两个两个求出差值加起来就可以了。。
然后错了。。
因为加起来的值不是INT,LONG LONG INT DOUBLE 都可以,改一下救过了呢~_~
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main()
{
int n;
int a[20001];
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<2*n;i++)
{
scanf("%d",&a[i]);
a[i]=fabs(a[i]);
}
sort(a,a+2*n);
double sum=0;
for(int i=1;i<=2*n-1;i=i+2)
{
sum=sum+a[i]-a[i-1];
}
printf("%.0lf\n",sum);
}
return 0;
}