#include <iostream> #include <strings.h> #include <stdio.h> #include <limits.h> typedef unsigned long long ULL; using namespace std; ULL n, v; ULL values[201719]; int fls(ULL x) { int ret = sizeof(ULL) * CHAR_BIT - 1; return x ? ret - __builtin_clzll(x) : ret; } int main() { cin >> n; for(ULL i=0; i<n; i++) { cin >> v; values[v]++; } ULL i=0, incr=0; while (n) { while (!values[i]) i++; incr = fls(values[i]); if (incr) { values[i+incr]++; n++; } n-=values[i++]; } cout << i-1 << endl; 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 | #include <iostream> #include <strings.h> #include <stdio.h> #include <limits.h> typedef unsigned long long ULL; using namespace std; ULL n, v; ULL values[201719]; int fls(ULL x) { int ret = sizeof(ULL) * CHAR_BIT - 1; return x ? ret - __builtin_clzll(x) : ret; } int main() { cin >> n; for(ULL i=0; i<n; i++) { cin >> v; values[v]++; } ULL i=0, incr=0; while (n) { while (!values[i]) i++; incr = fls(values[i]); if (incr) { values[i+incr]++; n++; } n-=values[i++]; } cout << i-1 << endl; return 0; } |