time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are nn students in a university. The number of students is even. The ii-th student has programming skill equal to aiai.

The coach wants to form n2n2 teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).

Students can solve problems to increase their skill. One solved problem increases the skill by one.

The coach wants to know the minimum total number of problems students should solve to form exactly n2n2 teams (i.e. each pair of students should form a team). Your task is to find this number.

Input

The first line of the input contains one integer nn (2≤n≤100) — the number of students. It is guaranteed that nn is even.

The second line of the input contains nn integers a1,a2,…,an (1≤ai≤100), where ai is the skill of the ii-th student.

Output

Print one number — the minimum total number of problems students should solve to form exactly n2n2 teams.

Examples

input

Copy

6
5 10 2 3 14 5

output

Copy

5

input

Copy

2
1 100

output

Copy

99

Note

In the first example the optimal teams will be: (3,4)(3,4), (1,6)(1,6) and (2,5)(2,5), where numbers in brackets are indices of students. Then, to form the first team the third student should solve 11 problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve 44 problems so the answer is 1+4=5.

In the second example the first student should solve 9999 problems to form a team with the second one.

题解:

这个题比第一题还水,求几个人需要做多少题才能一样,肯定就是排好序的从小到大,两个相邻的差值最小,这样最后的和才会最小

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream> using namespace std; int main()
{
int n;
cin>>n;
int sum=0;
int a[105];
for(int t=0;t<n;t++)
{
scanf("%d",&a[t]);
}
sort(a,a+n);
for(int t=0;t<n;t+=2)
{
sum+=a[t+1]-a[t];
}
cout<<sum<<endl;
return 0;
}

Codeforces Round #527-B. Teams Forming(贪心)的更多相关文章

  1. Codeforces Round #527 (Div. 3) ABCDEF题解

    Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...

  2. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  3. Codeforces Round #527 (Div. 3)

    一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...

  4. CodeForces Round #527 (Div3) B. Teams Forming

    http://codeforces.com/contest/1092/problem/B There are nn students in a university. The number of st ...

  5. Codeforces Educational Codeforces Round 3 C. Load Balancing 贪心

    C. Load Balancing 题目连接: http://www.codeforces.com/contest/609/problem/C Description In the school co ...

  6. Codeforces Round #547 (Div. 3) F 贪心 + 离散化

    https://codeforces.com/contest/1141/problem/F2 题意 一个大小为n的数组a[],问最多有多少个不相交的区间和相等 题解 离散化用值来做,贪心选择较前的区间 ...

  7. Educational Codeforces Round 12 C. Simple Strings 贪心

    C. Simple Strings 题目连接: http://www.codeforces.com/contest/665/problem/C Description zscoder loves si ...

  8. Codeforces Round #595 (Div. 3)D1D2 贪心 STL

    一道用STL的贪心,正好可以用来学习使用STL库 题目大意:给出n条可以内含,相交,分离的线段,如果重叠条数超过k次则为坏点,n,k<2e5 所以我们贪心的想我们从左往右遍历,如果重合部分条数超 ...

  9. Codeforces Round #554 (Div. 2) D 贪心 + 记忆化搜索

    https://codeforces.com/contest/1152/problem/D 题意 给你一个n代表合法括号序列的长度一半,一颗有所有合法括号序列构成的字典树上,选择最大的边集,边集的边没 ...

  10. Codeforces Round #303 (Div. 2) D 贪心

    D. Queue time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...

随机推荐

  1. SFTP 文件上传下载引用代码

    http://sha1064616837.iteye.com/blog/2036996 http://www.cnblogs.com/itmanxgl/p/fe5d33512609fe540eb08a ...

  2. ES禁用_source不会影响聚合

    From Elasticsearch's website: The _source field contains the original JSON document body that was pa ...

  3. 【Lintcode】070.Binary Tree Level Order Traversal II

    题目: Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from ...

  4. 【Lintcode】113.Remove Duplicates from Sorted List II

    题目: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct  ...

  5. element el-input 自动获取焦点和IE下光标位置解决方法

    在实际开发中我们经常会碰到这样的场景,就是有input的地方都喜欢切换过去input自动获取焦点. 如果这个问题是在input中,很容易就实现了,但是element里面的el-input看源码,其实不 ...

  6. 关于Tensorflow 加载和使用多个模型的方式

    在Tensorflow中,所有操作对象都包装到相应的Session中的,所以想要使用不同的模型就需要将这些模型加载到不同的Session中并在使用的时候申明是哪个Session,从而避免由于Sessi ...

  7. POJ3580:SuperMemo

    浅谈\(splay\):https://www.cnblogs.com/AKMer/p/9979592.html 浅谈\(fhq\)_\(treap\):https://www.cnblogs.com ...

  8. .NETFramework:StringBuilder

    ylbtech-.NETFramework:StringBuilder 1.程序集 mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken ...

  9. ASP.NET自定义控件组件开发

    ASP.NET的开发都是事件驱动的,现在我们就来为控件添加事件.在事件之前 对委托事件要要熟悉. 其实定义事件的步骤很简单: 1.声明一个委托. 2.定义一个携带事件信息的类. 3.定义事件 4.定义 ...

  10. 程序员必备,C#各类项目、开源项目插件资料收藏

    一.AOP框架     Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种部署方面 ...