/* -*- coding: utf-8 -*- * * 3281.cc: No.3281 Pacific White-sided Dolphin vs Monster - yukicoder */ #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; const int BN = 60; /* typedef */ using ll = long long; /* global variables */ ll hs[MAX_N]; /* subroutines */ bool check(int n, int x) { if (x > BN) n -= (x - BN), x = BN; if (n <= 0) return true; priority_queue q(hs, hs + n); for (int i = x - 1; ! q.empty() && i >= 0; i--) { ll bi = 1LL << i; auto h = q.top(); q.pop(); if (h > bi) q.push(h - bi); } return q.empty(); } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", hs + i); sort(hs, hs + n); int x0 = 0, x1 = n + BN; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; bool f = check(n, x); //printf(" check(%d,%d)=%d\n", n, x, f); if (f) x1 = x; else x0 = x; } printf("%d\n", x1); return 0; }