水题CodeForces - 1133C 找数字差不超过5的最多数

C - Balanced Team
You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is ai

.

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.

The first line of the input contains one integer n (1≤n≤2⋅105

) — the number of students.

The second line of the input contains n
integers a1,a2,…,an (1≤ai≤109), where ai is a programming skill of the i-th student.Print one integer — the maximum possible number of students in a balanced team.

Input

6
1 10 17 12 15 2

Output

3

Input

10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337

Output

10

题目大意:输入一组数,让你找出每个数之间差不大于5的数量。

**

**#include <iostream>
#include <algorithm>
using namespace std;
int a[200005];
int main()
{
    long long int i,j,n,cou=1,sum=1;
    cin>>n;
    for(i=1; i<=n; ++i)
        cin>>a[i];
    sort(a+1,a+1+n);
    for(i=1,j=2; i<=n&&j<=n&&i<=j;) //i<=j,it makes the sum will not be 0
    {
        if(a[j]-a[i]<=5)
            j++,sum++;
        else if(a[j]-a[i]>5)
            i++,sum--;
        cou=max(sum,cou);//!!!!!!!!
    }
    cout<<cou<<endl;//okay,max!
    return 0;
}**

**

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值