http://codeforces.com/contest/1092/problem/B

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≤1002≤n≤100) — the number of students. It is guaranteed that nn is even.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai 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=51+4=5.

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

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 1e5 + 10;
int N;
int a[maxn]; int main() {
scanf("%d", &N);
int ans = 0;
for(int i = 1; i <= N; i ++)
scanf("%d", &a[i]);
sort(a + 1, a + 1 + N); for(int i = 1; i <= N; i += 2)
ans += (a[i + 1] - a[i]); printf("%d\n", ans);
return 0;
}

  今日刷题目标:把这套 Div3 写完!

CodeForces Round #527 (Div3) B. Teams Forming的更多相关文章

  1. CodeForces Round #527 (Div3) D2. Great Vova Wall (Version 2)

    http://codeforces.com/contest/1092/problem/D2 Vova's family is building the Great Vova Wall (named b ...

  2. CodeForces Round #527 (Div3) D1. Great Vova Wall (Version 1)

    http://codeforces.com/contest/1092/problem/D1 Vova's family is building the Great Vova Wall (named b ...

  3. CodeForces Round #527 (Div3) C. Prefixes and Suffixes

    http://codeforces.com/contest/1092/problem/C Ivan wants to play a game with you. He picked some stri ...

  4. CodeForces Round #527 (Div3) A. Uniform String

    http://codeforces.com/contest/1092/problem/A You are given two integers nn and kk. Your task is to c ...

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

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

  6. 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3

    ◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...

  7. Codeforces Round #527 (Div. 3)

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

  8. Codeforces Round #527 (Div. 3) F. Tree with Maximum Cost 【DFS换根 || 树形dp】

    传送门:http://codeforces.com/contest/1092/problem/F F. Tree with Maximum Cost time limit per test 2 sec ...

  9. Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...

随机推荐

  1. CTF-安恒19年二月月赛部分writeup

    CTF-安恒19年二月月赛部分writeup MISC1-来玩个游戏吧 题目: 第一关,一眼可以看出是盲文,之前做过类似题目 拿到在线网站解一下 ??41402abc4b2a76b9719d91101 ...

  2. 20155202 《Java程序设计》实验一(Java开发环境的熟悉)实验报告

    20155202 <Java程序设计>实验一(Java开发环境的熟悉)实验报告 一.实验内容及步骤 使用JDK编译.运行简单的java程序 命令行下的程序开发 一(新建文件夹): 打开wi ...

  3. 2016-2017-2 《Java程序设计》第3周学习总结

    20155202张旭 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 第四章:认识对象: java两个类型系统:基本类型,类类型. 定义"构造函数& ...

  4. 20155218 2006-2007-2 《Java程序设计》第一周学习总结

    20155218 2006-2007-2 <Java程序设计>第1周学习总结 教材学习内容总结 浏览教材每章提出一个问题 组建如何与容器互动 PATH与classpath的对比 java的 ...

  5. 20155322 2016-2017-2 《Java程序设计》第9周学习总结

    20155322 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 第9周学习的主要内容是课本的第十六.第十七.第十八章,老师的教学指导上主要要求学习以下知识点 ...

  6. 20155338 2016-2017-2 《Java程序设计》第九周学习总结

    20155338 2016-2017-2 <Java程序设计>第九周学习总结 教材学习内容总结 第十六章 整合数据库 JDBC入门 · 数据库本身是个独立运行的应用程序 · 撰写应用程序是 ...

  7. [2016北京集训测试赛5]小Q与内存-[线段树的神秘操作]

    Description Solution 哇真的异常服气..线段树都可以搞合并和拆分的啊orzorz.神的世界我不懂 Code #include<iostream> #include< ...

  8. 【SQLSERVER】递归查询算法实例

    一.递归查询 1.结构: 递归CTE最少包含两个查询(也被称为成员). 第一个查询为定点成员,定点成员只是一个返回有效表的查询,用于递归的基础或定位点. 第二个查询被称为递归成员,使该查询称为递归成员 ...

  9. 【LG4091】[HEOI2016/TJOI2016]求和

    [LG4091][HEOI2016/TJOI2016]求和 题面 要你求: \[ \sum_{i=0}^n\sum_{j=0}^iS(i,j)*2^j*j! \] 其中\(S\)表示第二类斯特林数,\ ...

  10. Mysql:存储过程游标不进循环的原因详解

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客给刚接触存储过程的朋友做个引导作用,目的是解决游标不走循环 很多人发现他的游标,无论是嵌套循环还是单层 ...