E. Boxers

Problem

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根柱子站在一排,现在每根竹子都想变得独特起来,不希望和别得竹子一样(竹子要不一样就只有身高了)。 
现在,我是上帝,我来制定了一个规则,现在每根竹子都可以切自身的一截或者生长一截(一截的长度为1米)。 
注意:每根竹子的高度变化不能超过1米,并且每根竹子的高度始终为正整数。 
       现在,你需要找出在变化之后的这n根竹子中,有多少根不同的竹子。 
       竹子的变化可能会到150001米,但不会超过150001米. 

例如:
       在第一个样例中,每根竹子不需要改变身高就能取到最优解。 
       在第二个样例中,一个高度为1的竹子可以生长一截(得到2的高度),一个高度为4的竹子可以切一截(得到3的高度),另一个4可以生长一截(得到4的高度)。因此,你可以组建一支由5、4、3、2、1等高的不同的竹子。 

思路:

       首先,给N个数从小到大排序,然后按照从一个数的左边到自己到右边的顺序进行标记判断,满足条件即累加,不满足就判断下一个数,最后输出和,问题解决

 

C++提交代码:

#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

ll n,a[150005],is[150005];

int main()
{
    while(~scanf("%lld",&n)) {
        memset(is,0,sizeof(is));          //初始化状态,因为是多个测试用例
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a,a+n);

        ll sum = 0;   //最优解
        for(int i = 0; i < n; i++) {
            if(is[a[i]-1] == 0 && a[i] != 1) {     //先判断该数的左边
                sum++;
                is[a[i-1]] = 1;
            }
            else if(is[a[i]] == 0 ) {       //左边不满足,判断该数位置
                sum++;
                is[a[i]] = 1;
            }
            else if(is[a[i]+1] == 0) {    //该数本身位置不满足,判断右边
                sum++;
                is[a[i]+1] = 1;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

 

每日一言:

不牺牲短暂的享乐和安逸,就换不来长久的保障和幸福

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值