CodeForces Round #527 (Div3) B. Teams Forming
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.
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.
Print one number — the minimum total number of problems students should solve to form exactly n2n2 teams.
6
5 10 2 3 14 5
5
2
1 100
99
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- 【赛时总结】◇赛时·V◇ Codeforces Round #486 Div3
◇赛时·V◇ Codeforces Round #486 Div3 又是一场历史悠久的比赛,老师拉着我回来考古了……为了不抢了后面一些同学的排名,我没有做A题 ◆ 题目&解析 [B题]Subs ...
- Codeforces Round #527 (Div. 3)
一场div3... 由于不计rating,所以打的比较浪,zhy直接开了个小号来掉分,于是他AK做出来了许多神仙题,但是在每一个程序里都是这么写的: 但是..sbzhy每题交了两次,第一遍都是对的,结 ...
- 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 ...
- 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 ...
随机推荐
- 17个C语言可以做的小案例项目
C语言是我们大多数人的编程入门语言,对其也再熟悉不过了,不过很多初学者在学习的过程中难免会出现迷茫,比如:不知道C语言可以开发哪些项目,可以应用在哪些实际的开发中……,这些迷茫也导致了我们在学习的过程 ...
- MySQL5.7.22版本的安装和调试
1:安装前的准备工作 需要的软件: boost_1_59_0.tar.gz,cmake-3.6.1.tar.gz,mysql-5.7.22.tar.gz 开始安装MySQL 2.1 检查cmake [ ...
- R语言(自定义函数、循环语句、管道函数)
学习R语言半年多了,以前比较注重统计方法上的学习,但是最近感觉一些基础知识也很重要.去年的参考资料是<R语言实战>,今年主要是看视频.推荐网易云课堂里的教程,很多资料都是很良心的~ 目前学 ...
- Opencv3.0-python: 编译报错color.cpp:7456: error: (-215) scn == 3 || scn == 4 的解决方案
结合Opencv3.0读取视频时,出现报错:C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:11111: error: ( ...
- express添加权限拦截
express通过中间件的方式添加权限拦截 示例代码如下 app.get('/logout', checkLogin); app.get('/logout', function(req, res) { ...
- 20155302 2016-2017-2 《Java程序设计》第十周学习总结
20155302 2016-2017-2 <Java程序设计>第十周学习总结 教材学习内容总结 网络编程的实质就是两个(或多个)设备(例如计算机)之间的数据传输. 网络最主要的优势在于共享 ...
- Qt QStringLiteral
zz 解释QStringLiteral 原文发表于woboq网站 QStringLiteral explained 转载 原作者: Olivier Goffart 译者:zzjin QStringL ...
- 同一个电脑配置两个Git问题
拿到公司电脑后,正常配置gitlab,以及设置邮箱等等,可以使用公司邮箱,以及一系列设置 git config --global user.name "userName" git ...
- JAVA验证码识别:基于jTessBoxEditorFX和Tesseract-OCR训练样本
JAVA验证识别:基于jTessBoxEditorFX和Tesseract-OCR训练样本 工具准备: jTessBoxEditorFX下载:https://github.com/nguyenq/jT ...
- 第六篇 native 版本的Postman如何通过代理服务器录制Web及手机APP请求
第四篇主要介绍了chrome app版本的postman如何安装及如何录制Web脚本,比较简单. 但是chrome app 版本和native 版本相比,对应chrome app 版本官方已经放弃支持 ...