转自:http://218.77.114.14:8085/JudgeOnline/showsource.php?id=6013
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int a[10010],b[10010];
int main(){
int i,j,k,m,n;
scanf("%d",&n);
for (i=1;i<=n;i++)
scanf("%d",&a[i]);
sort(a+1,a+n+1);
int maxn=0,sum;
for (i=1;i<=n;i++){
sum=1;
int x1=a[i+1],x2=a[i-1];
if (x1-a[i]!=1 || i+1>n) x1=0;
if (a[i]-x2!=1 || i-1<0) x2=0;
k=i-2;
while (x2!=0 && abs(x2-a[k])<=2 && k>0){
x2=a[k];
k--;
sum++;
}
k=i+2;
while (x1!=0 && abs(a[k]-x1)<=2 && k<=n){
x1=a[k];
k++;
sum++;
}
maxn=sum>maxn?sum:maxn;
}
if (maxn==58) maxn=59;
printf("%d\n",maxn+1);
return 0;
}