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
67
68
69
70
71
72
73
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
    int n,max=0,input,resztka,zbiory=0,a;
    bool test=false;
    cin>>n;
    vector<int> tab(n+1,0);
    for (int i=0;i<n;i++)
    {
        cin>>input;
        tab[input]++;
    }
    map<int,int> wielkosci;
    for (int i=0;i<=n;i++)
    {
        if (tab[i]!=0)
            wielkosci[tab[i]]++;
    }
    for (auto ti=wielkosci.rbegin();ti!=wielkosci.rend();zbiory++)
    {
        ti->second--;
        resztka=ti->first-1;
        for (auto it=wielkosci.begin();it->second!=0&&it->first<=ti->first;)
        {
            if (it->first*it->second<resztka)
            {
                resztka-=it->first*it->second;
                if (it==wielkosci.begin())
                {
                    a=it->first;
                    it++;
                    wielkosci.erase(a);
                }
                else
                {
                    wielkosci.erase(it->first);
                }
            }
            else
            {
                if (resztka%it->first==0)
                {
                    it->second-=resztka/it->first;
                    if (it->second==0)
                        wielkosci.erase(it->first);
                }
                else
                {
                    it->second-=resztka/it->first;
                    it->second--;
                    wielkosci[it->first-resztka]++;
                    if (it->second==0)
                        wielkosci.erase(it->first);
                }
                break;
            }
            if (test)
            {
                it++;
            }
            else
                test=false;
        }
        if (ti->second==0)
        {   
            wielkosci.erase(ti->first); 
        }
    }
    cout<<zbiory;
}