# Boxers CodeForces - 1203E （贪心解法）——26行代码AC

## 立志用更少的代码做更高效的表达

There are n boxers, the weight of the i-th boxer is ai. Each of them can change the weight by no more than 1 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 ​ai will find the maximum possible number of boxers in a team.

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

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

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

Input
4
3 2 4 1

Output
4

Input
6
1 1 1 4 4 4

Output
5

#### 代码展示

#include<bits/stdc++.h>
using namespace std;
int a[150005];
int main() {
ios::sync_with_stdio(false);
int n; while(cin>>n) {
priority_queue<int, vector<int>, less<int> >q;	//降序队列
for(int i = 0; i < n; i++) {
int x; cin>>x;
q.push(x);
}
memset(a, 0, sizeof(a));		//重置a数组

for(int i = 0; i < n; i++) {
int x; x = q.top();
if(a[x+1] == 0) a[x+1] = 1;
else if(a[x]==0) a[x] = 1;
else if(a[x-1]==0 && x!=1) a[x-1] = 1;
q.pop();
}

int num=0;
for(int i = 0; i < 150005; i++) {
if(a[i] == 1)  num++;
}
cout << num << endl; /* */
}
return 0; }


10-13 265

10-07 188
08-14 125
08-17 103
08-15 248
08-15 130
08-19 49
08-14 50
11-28 241
08-14 189
08-15 244
08-17 279