src2020/4081_npeople/npeople.cpp

31 lines
602 B
C++

#include <iostream>
#include<algorithm>
using namespace std;
int n,a[100000]={0};
int mins(){
if(a[n-2]-a[0]==n-2&&a[n-1]-a[n-2]>n-2){
return 2;
}
if(a[n-1]-a[1]==n-2&&a[1]-a[0]>n-2){
return 2;
}
int ans=0,j=0;
for(int i=0;i<n;i++){
int now=a[i]+n;
while(j<n&&a[j]<now){
j++;
}
ans=max(j-i,ans);
}
return n-ans;
}
int main()
{
cin >> n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
cout<<mins()<<endl;
cout << max(a[n-2]-a[0],a[n-1]-a[1])-n+2;
}