IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 人工智能 -> 【无标题】 -> 正文阅读

[人工智能]【无标题】

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 - Codeforcesicon-default.png?t=LBL2https://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比的话,就会导致变成另一种内循环的模式.

  人工智能 最新文章
2022吴恩达机器学习课程——第二课(神经网
第十五章 规则学习
FixMatch: Simplifying Semi-Supervised Le
数据挖掘Java——Kmeans算法的实现
大脑皮层的分割方法
【翻译】GPT-3是如何工作的
论文笔记:TEACHTEXT: CrossModal Generaliz
python从零学(六)
详解Python 3.x 导入(import)
【答读者问27】backtrader不支持最新版本的
上一篇文章      下一篇文章      查看所有文章
加:2022-01-17 11:30:57  更:2022-01-17 11:32:49 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/20 17:24:04-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码