1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>

using namespace std;

vector<pair<long long, int>>zli;

bool check;
int n, res, sb, iter = 0, si, si1;
long long p;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        check = false;
        cin >> p;
        for(int j = 0; j < zli.size(); j++)
        {
            if(p==zli[j].first)
            {
                zli[j].second++;
                if(j!=0)
                {
                    if(zli[j].second>zli[j-1].second)
                    {
                        swap(zli[j], zli[j-1]);
                    }
                }
                check = true;
            }
        }
        if(check == false)
        {
            zli.push_back({p,1});
        }
    }
    if(zli[0].second>n/2)
    {
        cout << "1";
        return 0;
    }
    si = zli.size();
    si1 = si;
    bool tab[si] = {false};
    do
    {
        res++;
        sb = zli[iter].second;
        si1--;
        for(int i = iter + 1; i < si; i++)
        {
            if(sb>zli[i].second && tab[i] == false)
            {
                sb-=zli[i].second;
                tab[i]= true;
                si1--;
                if(sb<=1)
                    break;
            }
        }
        iter++;
    }while(si1>0);
    cout << res;
    return 0;
}