C. Balanced Team

C. Balanced Team

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are a coach at your local university. There are nn students under your supervision, the programming skill of the ii-th student is aiai.

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 55.

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 nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of students.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109), where aiai is a programming skill of the ii-th student.

Output

Print one integer — the maximum possible number of students in a balanced team.

Examples

input

Copy

6
1 10 17 12 15 2

output

Copy

3

input

Copy

10
1337 1337 1337 1337 1337 1337 1337 1337 1337 1337

output

Copy

10

input

Copy

6
1 1000 10000 10 100 1000000000

output

Copy

1

Note

In the first example you can create a team with skills [12,17,15][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).

Problem - 1133C - Codeforceshttps://codeforces.com/problemset/problem/1133/C

#include<iostream>
using namespace std;
#include<string>
#include<algorithm>
#pragma warning (disable:4996)
#include <climits>
#include <vector>
int arr[10000000];
int max(int a, int b);
int main() {
    int n;
    cin >> n;
    for (int cnt = 0; cnt < n; cnt++) {
        cin >> arr[cnt];
    }
    sort(arr, arr + n);
    int ans = 0;
    for (int cnt = 0,i=1; cnt < n; cnt++) {
        int temp = 0;
        while (arr[i] - arr[cnt] <= 5 && i < n)
            temp++, i++;
        ans = max(ans, i - cnt);
    }
    cout << ans;
    return 0;
}
int max(int a, int b) {
    return a > b ? a : b;
}

我踩过的坑:因为这道题我修改了下,按照上面内循环的方式的话,就是锁定最后一个,然后如果用temp和ans比的话,就会导致变成另一种内循环的模式.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

cjz-lxg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值