Codeforces Round #870 (Div. 2) A. Trust Nobody

题解

#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int>P;
const int maxn = 1e5 + 10;
const ll mod = 1e9 + 7;

bool cmp(int x, int y)
{
    return x > y;
}

int main()
{
    int t, n;
    int a[110];
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        sort(a+1, a+n+1, cmp);
        int cnt_liar = 0, mark = 1;
        int tmp = a[1];
        bool f = 0;
        for(int i = 1; i <= n;)
        {
            while(a[i] == tmp) i++;
            // cout << cnt_liar << ' ' << i << endl;
            if(cnt_liar >= a[i-1])
            {
                printf("%d\n", cnt_liar);
                f = 1;
                break;
            }
            cnt_liar += i - mark;
            if(cnt_liar >= a[i-1])
            {
                f = 0;
                break;
            }
            mark = i;
            tmp = a[i];
        }
        if(!f) printf("-1\n");
    }
    return 0;
}
posted @ 2023-10-17 20:22  .Ivorelectra  阅读(17)  评论(0编辑  收藏  举报