Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 3), problem: (E) Santa Claus and Tangerines Solution in C/C++

Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 – Elimination Round 3), problem: (E) Santa Claus and Tangerines Solution in C/C++

 

#include<stdio.h>
typedef long long unsigned llu;
typedef unsigned u;
u T[1111111],n,s;
u G(u y,u x)
{
if(y<x)return 0;
u z,r=1,a=0,b=0;
for(z=y;z>=x;z>>=1,++b)r<<=1;r>>=1;
if(z+1==x)a=y&((1u<<b)-1);
return r>a?r:a;
}
u F(u x)
{
u i;llu r=0;
for(i=-1;++i<n;)r+=G(T[i],x);
return r;
}
int main()
{
u i=-1,lo=0,hi=10000001,mi;
for(scanf(“%u%u”,&n,&s);++i<n;)scanf(“%u”,T+i);
while((mi=(lo+hi)>>1)>lo)
{
if(F(mi)>=s)lo=mi;
else hi=mi;
}
printf(lo?”%u\n”:”-1\n”,lo);
return 0;
}

(Visited 31 times, 1 visits today)

About the Author:

Leave A Comment