Problem Description

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≤iN)
  • ai is an integer.

Input

The input is given from Standard Input in the following format:

N
a1 a2 .. aN

Output

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

Example

Sample Input 1

7
3 1 4 1 5 9 2

Sample Output 1

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.

Sample Input 2

10
0 1 2 3 4 5 6 7 8 9

Sample Output 2

3

Sample Input 3

1
99999

Sample Output 3

1

题意:给一个长度为 n 的整数序列,对于序列中的每一个数可以进行一次操作,可以对其 +1、-1 或不做任何操作,对这 n 个数进行一次操作后,问序列中次数出现最多的数

思路:由于给出的数 ai 的值不大,可以利用桶排,对于每个数将其 +1、-1、原值均存入桶中,最后扫一遍桶,桶中元素最大值就是答案,需要注意的是,由于 ai 最小可能为 0,将其 -1 后值为 -1,因此桶需要整体向右偏移一个

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 100000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;int bucket[N];
int main() {int n;scanf("%d",&n);for(int i=1;i<=n;i++){int x;scanf("%d",&x);x++;//向右偏移bucket[x]++;bucket[x-1]++;bucket[x+1]++;}int maxx=-INF;int res=0;for(int i=1;i<=1E5+1;i++)maxx=max(maxx,bucket[i]);printf("%d\n",maxx);return 0;
}

Together(AtCoder-3524)相关推荐

  1. AtCoder Beginner Contest 198 (A ~ F)题解

    目录 A. Div B. Palindrome with leading zeros C. Compass Walking D. Send More Money E. Unique Color F. ...

  2. UPC个人训练赛第十五场(AtCoder Grand Contest 031)

    传送门: [1]:AtCoder [2]:UPC比赛场 [3]:UPC补题场 参考资料 [1]:https://www.cnblogs.com/QLU-ACM/p/11191644.html B.Re ...

  3. Mynavi Programming Contest 2021(AtCoder Beginner Contest 201)题解

    文章目录 A - Tiny Arithmetic Sequence B - Do you know the second highest mountain? C - Secret Number D - ...

  4. KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200)题解

    文章目录 A - Century B - 200th ABC-200 C - Ringo's Favorite Numbers 2 D - Happy Birthday! 2 E - Patisser ...

  5. freee Programming Contest 2022(AtCoder Beginner Contest 264)A~D题详细讲解

    目录 博主赛情 网站链接 比赛简介 Contest Information Reason why freee needs AtCoder users freee's business content ...

  6. 【解题报告系列】超高质量题单 + 题解(ACM / OI)超高质量题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 繁凡出品的全新系列:解题报告系列 -- 超高质量算法题单,配套我新写的超高质量的题解和代码,题目难度不 ...

  7. 深入探索Android内存优化(炼狱级别)

    本文由 jsonchao投稿 微信:bcce5360 前言 成为一名优秀的Android开发,需要一份完备的知识体系,在这里,让我们一起成长为自己所想的那样~. 本篇是 Android 内存优化的进阶 ...

  8. coco数据集(yoloV5格式)中生成子类数据集

    从coco数据集(yoloV5格式)中生成子类数据集. import os from tqdm import tqdmnames = ['person', 'bicycle', 'car', 'mot ...

  9. SPSS(十一)SPSS信息浓缩技术--主成分分析、因子分析(图文+数据集)

    SPSS(十一)信息浓缩技术--主成分分析.因子分析(图文+数据集) 当我们的自变量存在多重共线性,表现为进行回归时候方程系数估计不正常以及方程检验结果不正常,也许我们可以使用变量挑选的办法(手动挑选 ...

  10. 惹某人de集训第4周学习摘录(习题+感悟)

    我是个没有感情的WA题机器 (一)课堂内容 创建二叉树 根据先序遍历和中序遍历建树输出后序遍历 贪心!贪心! 归并排序经典题 题目描述 Input Output Sample Input Sample ...

最新文章

  1. linux怎样标识空设备,Linux系统命令------Ubuntu下解决adb设备列表为空
  2. linux yum源安装
  3. 《计算机图形学》2.2.2 光栅扫描显示处理器
  4. io密集型和cpu密集型_一次说明白Python爬虫中多线程,多进程,异步IO编程
  5. DXUT框架剖析(1)
  6. 解除网页百度云自动关联客户端,可通过迅雷或浏览者下载
  7. matlab基础与应用教程 王月明,MATLAB基础与应用教程
  8. xshell 安装包(百度网盘)+安装过程连接虚拟机注意事项
  9. Android日历阴阳历转换的实现(包括日期选择器)
  10. 注册google账号,当前时间方法仍可用
  11. 单声道120W大功率D类功放芯片CS8683-TPA3116对比测试
  12. 2019各种比赛总结
  13. 图标照旧的效果_这不是而且不能成为“一切照旧”
  14. 禁用Win10截屏快捷键Win+Shift+S,改用Snipaste
  15. win10 nas搭建_零起步自建家用NAS
  16. mysql查询优化方案
  17. C语言程序设计基础知识——谭浩强版
  18. java/php/net/python线上歌唱比赛报名系统设计
  19. Unity2d学习笔记(一)添加角色地图并且实现人物移动
  20. EasyCVR国标GB28181协议接入下的TCP和UDP模式说明及差异

热门文章

  1. [置顶]LGame框架问题汇总,有疑问请发至此文
  2. linux内核start_kernel分析
  3. STM32之串口例程
  4. Linux调试时常见问题,C程序在linux下调试时经常出现的问题
  5. 漫话:如何给女朋友解释为什么Java线程没有Running状态?
  6. JEECG_3.7.2新版本入门讲解—UI标签库专题
  7. 如何在PAI平台跑实验
  8. Redis命令——键(key)
  9. vue2.0项目结构和打包发布
  10. Linux 关闭网络管理服务