Codeforces Round #544 (Div. 3) Editorial C. Balanced Team
http://codeforces.com/contest/1133/problem/C
time limit per test 2 seconds
memory limit per test 256 megabytes
inputstandard input
outputstandard output
You are a coach at your local university. There are $n$ students under your supervision, the programming skill of the i-th student is $a_i$.
You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than 5.
Your task is to report the maximum possible number of students in a balanced team.
Input
The first line of the input contains one integer $n$($1≤n≤2⋅10^5$) — the number of students.
The second line of the input contains $n$ integers $a_1,a_2,…,a_n$($1≤a_i≤10^9$), where $a_i$ is a programming skill of the i-th student.
Output
Print one integer — the maximum possible number of students in a balanced team.
Examples
input
6
1 10 17 12 15 2
output
3
input
10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
output
10
input
6
1 1000 10000 10 100 1000000000
output
1
Note
In the first example you can create a team with skills [12,17,15].
In the second example you can take all students in a team because their programming skills are equal.
In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).
解题思路
官方:Let's sort all values in non-decreasing order. Then we can use two pointers to calculate for each student
Codeforces Round #544 (Div. 3) Editorial C. Balanced Team的更多相关文章
- Codeforces Round #544 (Div. 3) E. K Balanced Teams (DP)
题意:有\(n\)个人,每个人的能力值是\(a_i\),现在你想将这些人分成\(k\)组(没必要全选),但是每组中最高水平和最低水平的人的能力差值必须\(\le 5\),问最多能选多少人. 题解:想了 ...
- Codeforces Round #544 (Div. 3) 题解
Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization 题目链接:https://codeforces.com/contest/113 ...
- Codeforces Round #590 (Div. 3) Editorial
Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同 ...
- Codeforces Round #747 (Div. 2) Editorial
Codeforces Round #747 (Div. 2) A. Consecutive Sum Riddle 思路分析: 一开始想起了那个公式\(l + (l + 1) + - + (r − 1) ...
- CodeForces Round #544 Div.3
A. Middle of the Contest 代码: #include <bits/stdc++.h> using namespace std; int h1, m1, h2, m2; ...
- Codeforces Round #544 (Div. 3)解题报告
A.Middle of the Contest 考虑把输入的时间单位化成分钟,相加除以2就好了 #include<bits/stdc++.h> using namespace std; # ...
- Codeforces Round #544 (Div. 3) C. Balanced Team
链接:https://codeforces.com/contest/1133/problem/C 题意: 给n个数, 在这n个数中选最多n个数,来组成一个队伍. 保证这n个数的最大最小差值不大于5. ...
- Codeforces Round #544 (Div. 3) dp + 双指针
https://codeforces.com/contest/1133/problem/E 题意 给你n个数(n<=5000),你需要对其挑选并进行分组,总组数不能超过k(k<=5000) ...
- Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization
链接:https://codeforces.com/contest/1133/problem/D 题意: 给两个数组a,b. 同时ci = ai * d + bi. 找到一个d使c数组中的0最多. 求 ...
随机推荐
- bzoj 1645: [Usaco2007 Open]City Horizon 城市地平线【线段树+hash】
bzoj题面什么鬼啊-- 题目大意:有一个初始值均为0的数列,n次操作,每次将数列(ai,bi-1)这个区间中的数与ci取max,问n次后元素和 离散化,然后建立线段树,每次修改在区间上打max标记即 ...
- Sql 主键设置
1.开发数据库时常用命名规范 1>.使用不包含数字的单数表名,如果必要的话可以增加模块名前缀. 2>.对于主键的命名,使用表名+ID的形式. 3>.作为外键的列的名字应该与它们所对应 ...
- WebSphere Application Server切换JAVA SDK版本
最近在Windows Server 2008 R2服务器中搭建了一套IHS+WAS8.5集群环境,测试一个简单的demo应用没有问题,可是在部署正式应用时总是报类版本错误.换了好几个JDK对项目进行编 ...
- 每天学点Linux命令之Linux-Shell中的数据重定向与管道命令
在Linux shell中, 数据重定向使用 > < 符号,管道命令使用 | 符号链接前后两个命令. 具体区别如下: 数据重定向 1.(>): 左侧应该有标准输出 > 右侧只能 ...
- 312 Burst Balloons 戳气球
现有 n 个气球按顺序排成一排,每个气球上标有一个数字,这些数字用数组 nums 表示.现在要求你戳破所有的气球.每当你戳破一个气球 i 时,你可以获得 nums[left] * nums[i] * ...
- Canvas入门笔记-实现极简画笔
今天学习了Html5 Canvas入门,已经有大神写得很详细了http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html#8 在学习过后 ...
- idea安装插件plugin(主要针对网络连接不上的情况)
https://blog.csdn.net/duoduo1636546/article/details/80104711
- Git在工作中对项目的操作流程
Git 的准备工作 第一步:Git初始化 第一次在电脑上使用时,应该初始化操作,以后再使用Git操作,无需初始化,直接进行Git其他操作 git config --global user.name & ...
- Android ListView绑定数据
ListView绑定数据的三层: ListView绑定数据源从逻辑上可以分为三层:UI层,逻辑层,数据层. UI层:UI层即是ListView控件. 数据层:要展示到ListView控件上面的数据. ...
- Linux系统命令及文件的浏览、管理和维护
在linux中什么是一个文件的路径呢,说白了就是这个文件存在的地方,例如在上一章提到的/root/.ssh/authorized_keys 这就是一个文件的路径.如果你告诉系统这个文件的路径,那么系统 ...