#include <cstdio> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) using namespace std; const int maxn = 1000010; int n; int maxa; int b[maxn]; int main() { scanf("%d", &n); int a; REP(i, n) { scanf("%d", &a); ++b[a]; if (a > maxa) { maxa = a; } } int carry = 0; int result = 0; for (int i = 0; i <= maxa || carry > 0; ++i) { carry = (carry + b[i])/2; result = i; } printf("%d\n", result); 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 | #include <cstdio> #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) using namespace std; const int maxn = 1000010; int n; int maxa; int b[maxn]; int main() { scanf("%d", &n); int a; REP(i, n) { scanf("%d", &a); ++b[a]; if (a > maxa) { maxa = a; } } int carry = 0; int result = 0; for (int i = 0; i <= maxa || carry > 0; ++i) { carry = (carry + b[i])/2; result = i; } printf("%d\n", result); return 0; } |