码迷,mamicode.com
首页 > 其他好文 > 详细

E. Boxers ( Codeforces Round #579 )

时间:2019-08-27 11:08:58      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:target   ram   val   ase   ems   end   you   int   lld   

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 (1n1500001≤n≤150000) — the number of boxers. The next line contains nn integers a1,a2,,ana1,a2,…,an, where aiai (1ai1500001≤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
Copy
4
3 2 4 1
output
Copy
4
input
Copy
6
1 1 1 4 4 4
output
Copy
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.

 

#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
typedef long long ll;
using namespace std;
const int INT=1e6+5;
#define lson rt<<1, l, m  
#define rson rt<<1|1, m+1, r
#define read(x) scanf("%d",&x)
#define lread(x) scanf("%lld",&x);
#define pt(x) printf("%d\n",(x))
#define cn cin>>
#define ct cout<<
#define en <<endl
#define rep(j,k) for (int i = (int)(j); i <= (int)(k); i++)
#define input(k) for (int i = 1; i <= (int)(k); i++)  {cin>>a[i] ; }
#define mem(s,t) memset(s,t,sizeof(s))
#define re return 0;
#define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int a[151000];
bool vis[151000];
int main()
{
    TLE;
    int n;
    scanf("%d",&n);
    for(int i = 1; i <= n; ++i) scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    int sum = 0;
    for(int i = 1; i <= n; ++i){
        if(!vis[a[i]-1] && a[i] != 1){ vis[a[i]-1] = true; sum++;continue; }
        if(!vis[a[i]]){ vis[a[i]] = true; sum++;continue; }
        if(!vis[a[i]+1]){ vis[a[i]+1] = true; sum++;continue; }
    }
    cout<<sum<<endl;
    return 0;
}

 

E. Boxers ( Codeforces Round #579 )

标签:target   ram   val   ase   ems   end   you   int   lld   

原文地址:https://www.cnblogs.com/Shallow-dream/p/11416516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!