Advertisement
K_Y_M_bl_C

Untitled

Dec 25th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. ll n;
  2. ll k;
  3. ll a[MAXN];
  4.  
  5. int check(ll x)
  6. {
  7.     ll cr = 0;
  8.     forn(i, n)
  9.     {
  10.         ll cur = 0;
  11.         if (x == 1)
  12.             cur = a[i];
  13.         else
  14.         {
  15.             ll q = a[i];
  16.             ll st = 0;
  17.             while (q >= x)
  18.                 q /= 2, ++st;
  19.             --st;
  20.             cur = (1ll << st);
  21.         }
  22.         cr += cur;
  23.         if (cr >= k)
  24.             return 1;
  25.     }
  26.     return 0;
  27. }
  28.  
  29. int solve()
  30. {
  31.     ll sum = 0;
  32.     scanf("%lld %lld", &n, &k);
  33.     forn(i, n)
  34.         scanf("%lld", &a[i]), sum += a[i];
  35.     if (sum < k)
  36.         puts("-1"), exit(0);
  37.     ll l = 1, r = (ll)1e7 + 1;
  38.     while (r - l > 1)
  39.     {
  40.         ll mid = l + r >> 1ll;
  41.         if (check(mid))
  42.             l = mid;
  43.         else
  44.             r = mid;
  45.     }
  46.     cout << l;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement