hiho week 187 register

Ended

Participants:129

Verdict:Accepted
Score:100 / 100
Submitted:2018-01-29 20:05:19

Lang:G++

Edit
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
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define fst first
#define snd second
int main(void) {
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<int, int> cnt;
    multiset<int> elem;
    for (int i = 0; i < N; ++ i) {
        int x;
        cin >> x;
        ++ cnt[x];
        elem.insert(x);
    }
    set<pii> cand;
    for (auto &p: cnt) cand.insert(pii(-p.snd, p.fst));
    if (-2 * cand.begin()->fst - N > 1) {
        cout << -1 << endl;
    } else {
        int prev = 0;
        while (N > 0) {
            int y = -cand.begin()->fst, x = cand.begin()->snd;
            if (2 * y - N == 1) {
                cand.erase(pii(-y, x));
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX