#include <cstdio> #include <vector> #include <algorithm> #include <map> using namespace std; #define LL long long int main() { LL a,n; vector<LL> ns; scanf("%lld", &n); while (n--) { scanf("%lld", &a); ns.push_back(a); } sort(ns.begin(), ns.end()); map<LL, LL> ps; LL prev = -1; LL cnt = 0; for (auto it = ns.begin(); it != ns.end(); it++) { if (*it != prev) { if (cnt != 0) { ps.insert(make_pair(prev, cnt)); } cnt = 1; prev = *it; } else { cnt++; } } ps.insert(make_pair(prev, cnt)); while (ps.size() != 1) { auto begin = ps.begin(); LL coin = begin->first + 1; LL cnt = begin->second / 2; ps.erase(begin); if (cnt > 0 && coin != 0) { if (ps.find(coin) != ps.end()) { ps[coin] = ps[coin] + cnt; } else { ps.insert(make_pair(coin, cnt)); } } } auto begin = ps.begin(); LL coin = begin->first; cnt = begin->second; while(cnt != 1) { coin++; cnt /= 2; } printf("%lld\n", coin); return 0; }
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 | #include <cstdio> #include <vector> #include <algorithm> #include <map> using namespace std; #define LL long long int main() { LL a,n; vector<LL> ns; scanf("%lld", &n); while (n--) { scanf("%lld", &a); ns.push_back(a); } sort(ns.begin(), ns.end()); map<LL, LL> ps; LL prev = -1; LL cnt = 0; for (auto it = ns.begin(); it != ns.end(); it++) { if (*it != prev) { if (cnt != 0) { ps.insert(make_pair(prev, cnt)); } cnt = 1; prev = *it; } else { cnt++; } } ps.insert(make_pair(prev, cnt)); while (ps.size() != 1) { auto begin = ps.begin(); LL coin = begin->first + 1; LL cnt = begin->second / 2; ps.erase(begin); if (cnt > 0 && coin != 0) { if (ps.find(coin) != ps.end()) { ps[coin] = ps[coin] + cnt; } else { ps.insert(make_pair(coin, cnt)); } } } auto begin = ps.begin(); LL coin = begin->first; cnt = begin->second; while(cnt != 1) { coin++; cnt /= 2; } printf("%lld\n", coin); return 0; } |