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 ...
随机推荐
- PL/SQL轻量版(二)——基本语法
一.流程控制 1.条件判断 语法: IF <布尔表达式> THEN PL/SQL 和 SQL语句 END IF; IF <布尔表达式> THEN PL/SQL 和 SQL语句 ...
- addClass+siblings+removeClass用意:
$(this).addClass("li_add").siblings().removeClass("li_add").children('.floor2'). ...
- superset 安装测试,基于windows 和 centos7.x
1.刚开始在windows平台测试搭建,报各种问题,搭建可以参考官网https://superset.incubator.apache.org/installation.html#deeper-sql ...
- Oracle用户和模式,表空间
oracle 用户与表空间关系 oracle用户与表空间关系用户=商家表=商品表空间=仓库1. 1个商家能有很多商品,1个商品只能属于一个商家2. 1个商品可以放到仓库A,也可以放到仓库B,但不能同时 ...
- [Bootstrap 源码解析]——bootstrap源码之初始化
bootstrap源码之初始化 我们先来分析normalize.less编译后的源码,我们知道normalize.css是一个专门将不同浏览器的默认css特性设置为统一效果的css库,它和reset. ...
- javaweb总结(四十)——编写自己的JDBC框架
一.元数据介绍 元数据指的是"数据库"."表"."列"的定义信息. 1.1.DataBaseMetaData元数据 Connection.g ...
- eclipse查看源代码问题
最近分析源代码时,eclipse总是出错,显示org.eclipse.core.runtime.CoreException,解决方法:在builderpath点击 add external jars, ...
- java excel导出(表头合并,多行表头)
@RequestMapping(value="orderExcelList2") public void orderExcelList2forJava(Order order,Ht ...
- Linux 安装FastDFS<单机版>(使用Mac远程访问)
阅读本文需要先阅读安装FastDFS<准备> 一 编译环境 yum install gcc-c++ yum -y install libevent yum install -y pcre ...
- Unity3D之AR开发(二)
上一篇给大家介绍了高通AR的使用,接下来给大家分享一下EasyAR EasyAR引擎简介 EasyAR是做好用的且免费的增强现实(Augmented Reality)引擎,EasyAR为Unity开发 ...