E. Boxers(贪心)

There are nn boxers, the weight of the ii-th boxer is aiai. Each of them can change the weight by no more than 11 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.

It is necessary to choose the largest boxing team in terms of the number of people, that all the boxers' weights in the team are different (i.e. unique).

Write a program that for given current values ​aiai will find the maximum possible number of boxers in a team.

It is possible that after some change the weight of some boxer is 150001150001 (but no more).

Input

The first line contains an integer nn (1≤n≤1500001≤n≤150000) — the number of boxers. The next line contains nn integers a1,a2,…,ana1,a2,…,an, where aiai (1≤ai≤1500001≤ai≤150000) is the weight of the ii-th boxer.

Output

Print a single integer — the maximum possible number of people in a team.

Examples

input

4
3 2 4 1

output

4

input

6
1 1 1 4 4 4

output

5

Note

In the first example, boxers should not change their weights — you can just make a team out of all of them.

In the second example, one boxer with a weight of 11 can be increased by one (get the weight of 22), one boxer with a weight of 44 can be reduced by one, and the other can be increased by one (resulting the boxers with a weight of 33 and 55, respectively). Thus, you can get a team consisting of boxers with weights of 5,4,3,2,15,4,3,2,1.

题意:有n个拳击运动员,每个人在比赛前可以改变一斤体重,询问比赛时最多能带几个不同体重的运动员。

思路:先排序,从大到小,优先想加一斤体重,再不变,最后考虑减一斤体重。

代码:

#include <bits/stdc++.h>using namespace std;typedef long long ll;
const int N = 2e5+10;int via[N];
int a[N];
int n;int main()
{int i,j,k;scanf("%d", &n);for ( i=1; i<=n; i++ ) {cin >> a[i];}sort(a+1,a+n+1,greater<int>());int ans = 0;for ( i=1; i<=n; i++ ) {if ( via[a[i]+1]==0 ) {via[a[i]+1] = 1;ans ++;}else if ( via[ a[i] ]==0 ) {via[ a[i] ] = 1;ans ++;}else if ( via[ a[i]-1 ]==0 && a[i]-1>0 ) {via[ a[i]-1 ] = 1;ans ++;}}cout << ans << endl;return 0;
}

E. Boxers(贪心)相关推荐

  1. codefrces 1203 E. Boxers(贪心)

    E. Boxers time limit per test 2 seconds memory limit per test 256 megabytes input standard input out ...

  2. codeforces 1203 E Boxers 贪心

    https://codeforces.com/problemset/problem/1203/E 题目大意:给 n n n个数,每个数可以做两种变化:(1) + 1 +1 +1:(2) − 1 -1 ...

  3. Codeforces Round #579 (Div. 3) E. Boxers (贪心)

    题目链接:https://codeforces.com/contest/1203/problem/E 思路:一开始想的是记录数字出现次数,看每个数字的三种变化能否产生新数,但是这样容易多算或者少算答案 ...

  4. Codeforces 1203E Boxers(贪心)

    题目链接:https://codeforces.com/problemset/problem/1203/E 题意:给定n个数字,每个数字可以进行一次+1或是-1的变换(也可以不变),问通过对部分数字适 ...

  5. Boxers CodeForces - 1203E (贪心解法)——26行代码AC

    立志用更少的代码做更高效的表达 There are n boxers, the weight of the i-th boxer is ai. Each of them can change the ...

  6. E. Boxers(贪心+移出多余空位)

    题意:给你n个数,然后你只能对一个数做一次操作使得这个数组里面的不同的数个数最多: 操作: 1.你可以对一个数-1(注意体重不能为0): 2.你可以对一个数+1: 3.你可以对这个数不做修改: 这道题 ...

  7. Codeforces Round #579 (Div. 3)--Boxers(贪心,排序)

    题目链接 题意: 给定n个质量为ai的盒子,每个盒子质量都可以改变不超过1的单位质量,求能够选出的互不相同的质量的盒子的最大数目. 题目条件: 1<=n<=150000,1<=ai& ...

  8. Codeforces Round #579 (Div. 3), problem: (E) Boxers【贪心】

    题目链接 题目大意 有n个拳击运动员,每个人在比赛前可以改变一斤体重,询问比赛时最多能带几个不同体重的运动员 题解 先排序,从大到小,优先先加一斤体重,再不变,最后考虑减一斤体重 #include&l ...

  9. E. Boxers Div3

    E. Boxers 题意 给n个元素,你可以对每个元素选择加一或者减一或者不变,问最后怎么样可以使不同的数量最多. 思路 贪心+模拟 我们可以把每一个数都记下来出现过几次,我们从1枚举到元素的最大值, ...

最新文章

  1. java中路径中参数化_Azure数据工厂:参数化文件夹和文件路径
  2. 从ASP.NET传递参数给水晶报表
  3. 修改anaconda中conda和pip的源为清华源
  4. 每天一道LeetCode----从数组中选择若干不连续元素使得总和最大
  5. 计算机专业的一个四年工作的总结
  6. Web 开发中 Blob 与 FileAPI 使用简述
  7. SpringBoot配置图片虚拟映射
  8. 7款最佳jQuery和JavaScript的PDF查看器插件
  9. c语言编程继承例子,C语言模拟实现C++的继承与多态示例
  10. 面向对象思想的设计原则概述
  11. 直接无序搜索 vs 先排序后搜索
  12. 判断是否是完全二叉树_二叉树:我对称么?
  13. linux 神舟z7,老船长带你神舟战神Z7使用进阶
  14. hadoop进阶---hadoop性能优化(一)---hdfs空间不足的管理优化
  15. PD快速充电协议(转)
  16. 讲解c程序设计语言的比喻,《C语言程序设计》论文关于比喻在《C语言程序设计》课程教学中的应用论文范文参考资料...
  17. 比较两个数或者三个数的大小,输出较大数的值 Java
  18. 我的世界服务器怎么弄无限矿物,《我的世界》无限存储空间设备如何制作?
  19. Win10电脑怎么更改UEFI固件设置
  20. selenium定位H5表单验证的提示语

热门文章

  1. google地图静态下载和js调用
  2. 名企实习学历受限吗?IT名企实习看实力还是学历?
  3. AEcs4输出是After Effects:Out of memry(16200k requested) (23::40) 什么意思?
  4. Keynote特效案例集
  5. 零基础带你硬核了解并上手“Ansible“!
  6. 怎样既快又省地搞好仪表采购
  7. python动画精灵_Python精灵模块简介
  8. MySQL数据库大作业——学生管理系统GUI
  9. 鼻炎康片怎么样 功效与作用有哪些?
  10. 道道通导航linux升级,道道通导航升级2020冬季版