比赛 4043级NOIP2022欢乐赛7th 评测结果 AEWEEEEEEW
题目名称 愤怒的奶牛 最终得分 10
用户昵称 张恒畅 运行时间 1.245 s
代码语言 C++ 内存使用 4.01 MiB
提交时间 2022-11-20 10:49:21
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
const int N = 110, INF = 2e9;
int n;
int q[N];
int main()
{
	freopen( "angry.in", "r", stdin);
	freopen( "angry.out", "w", stdout);
    scanf("%d",&n);
    q[0] = -INF,q[n + 1] = INF;
    for(int i = 1;i <= n;i ++) scanf("%d",&q[i]);
    sort(q + 1,q + n + 1);
    int res = 0;
    for(int i = 1;i <= n;i ++)
    {
        int l = 1,r = 1,a = i,b = i;
        while(q[a] - q[a - 1] <= l)
        {
            int k = a - 1;
            while(q[a] - q[k - 1] <= l) k--;
            a = k;
            l++;
        }
        while(q[b + 1] - q[b] <= r)
        {
            int k = b + 1;
            while(q[k + 1] - q[b] <= r) k++;
            b = k;
            r++;
        }
        res = max(res,b - a + 1);
    }
    cout << res  <<".0"<< endl;
    return 0;
}