K: Together

问题 K: Together
时间限制: 1 Sec 内存限制: 128 MB
提交: 371 解决: 197
[提交] [状态] [讨论版] [命题人:admin]
题目描述

You are given an integer sequence of length N, a1,a2,…,aN.
For each 1≤i≤N, you have three choices: add 1 to ai, subtract 1 from ai or do nothing.
After these operations, you select an integer X and count the number of i such that ai=X.
Maximize this count by making optimal choices.

Constraints
1≤N≤105
0≤ai<105(1≤i≤N)
ai is an integer.

输入

The input is given from Standard Input in the following format:
N
a1 a2 .. aN

输出

Print the maximum possible number of i such that ai=X.

样例输入

7
3 1 4 1 5 9 2

样例输出

4

提示

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.
思路:枚举统计

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define M 3*100005
using namespace std;
struct node
{
    int e;
    int cnt;
};
int main()
{
    int n,e;
    cin>>n;
    int res[M];
    memset(res,0,sizeof(res));
    int Max=-1;
    for(int i=0;i<n;i++)
    {
        cin>>e;
        res[e+1]++;
        res[e-1]++;
        res[e]++;
    }
    for(int i=0;i<M;i++)
        Max=max(Max,res[i]);
    printf("%d\n",Max);
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值