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 ...
 
随机推荐
- 《C语言程序设计基础1》第二学期第一周学习总结
			
**<C语言程序设计基础1>第二学期第一周学习总结 一. 本周学习内容总结 一维数组,了解了一维数组的定义(定义一个数组,需要明确数组变量名,数组元素的类型和数组大小,即数组中元素的数量) ...
 - bat脚本,winscp,shell加mysql存储过程实现mysql单条数据迁移
			
起因 公司有个任务,需要迁移mysql中的单条数据.从公司的dev环境到staging环境,dev环境的mysql安装在windows server 2012 R2下,stage是aws的服务器不能直 ...
 - Vue2.5入门-2
			
todolist功能开发 代码 <!DOCTYPE html> <html> <head> <title>vue 入门</title> &l ...
 - # 20155224 实验四 Android程序设计
			
20155224 实验四 Android程序设计 任务一 Android Stuidio的安装测试: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java for And ...
 - texterea 水平居中
			
例子:<div style="width: 100%;text-align: center;"> <textarea class="xinde_msg& ...
 - CF543E Listening to Music
			
题面 空间只有$64\text{MB}$!!! 题解 (据说正解是毒瘤分块套分块) 按照权值从大到小排序,对所有能够覆盖到它的区间的左端点打个标记 按照值域建一棵主席树就可以了 区间查询最大值,用$m ...
 - 12、Java并发编程:阻塞队列
			
Java并发编程:阻塞队列 在前面几篇文章中,我们讨论了同步容器(Hashtable.Vector),也讨论了并发容器(ConcurrentHashMap.CopyOnWriteArrayList), ...
 - JS 判断checkbox 是否选中
			
<input type="checkbox" id="IsEnable" /> 在调试的时候,会出现,一直未true的状态,不管是选中还是未选中 解 ...
 - 类的扩展之 DataReader的扩展
			
看了关于DataReader的扩展,发现能节省很多代码.从数据库读取数据最原始方法就是while()然后做循环,如果数据库添加一个字段那么你所有读取数据库的方法全部添加.通过扩展这个类就摆脱了这种令人 ...
 - Maven学习(二)-----Maven启用代理访问
			
Maven启用代理访问 如果你的公司正在建立一个防火墙,并使用HTTP代理服务器来阻止用户直接连接到互联网.如果您使用代理,Maven将无法下载任何依赖. 为了使它工作,你必须声明在 Maven 的配 ...