题目链接:https://codeforces.com/problemset/problem/1283/E
题目大意:
转大佬的博客:https://blog.csdn.net/m0_38055352/article/details/103816016

#include <bits/stdc++.h>
#define LL long long
using namespace std;

set<int> s;
int a[200010], vis[200010];
int main(){

    int n;scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%d", &a[i]);
        s.insert(a[i]);
    }
    int L=-10, MIN=0, MAX=0;
    for(set<int>::iterator p=s.begin(); p!=s.end(); p++){
        int x=*p;
        if(L+2<x){
            MIN++;
            L=x;
        }
    }
    sort(a+1, a+n+1);
    for(int i=1; i<=n; i++){
        if(!vis[a[i]-1]){
            vis[a[i]-1]=1;
            MAX++;
        }
        else if(!vis[a[i]]){
            vis[a[i]]=1;
            MAX++;
        }
        else if(!vis[a[i]+1]){
            vis[a[i]+1]=1;
            MAX++;
        }
    }
    printf("%d %d\n", MIN, MAX);

    return 0;
}