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

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

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?#8221;%u\n”:”-1\n”,lo);
return 0;
}

📦 Looking for Codeforces Round 389 Div Based Technocup? Check the best deals on Amazon.

🛒 Shop Codeforces Round 389 Div Based Technocup on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

Affiliate Disclosure: This post contains Amazon affiliate links. If you purchase through these links, eBlogarithm may earn a commission at no extra cost to you. Prices and availability are subject to change.

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?#8221;%u\n”:”-1\n”,lo);
return 0;
}

📦 Looking for Codeforces Round 389 Div Based Technocup? Check the best deals on Amazon.

🛒 Shop Codeforces Round 389 Div Based Technocup on Amazon

As an Amazon Associate, eBlogarithm earns from qualifying purchases. Prices and availability are subject to change.

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

Empire of the Sun’s 2027 Tour of Australasia Will Be Their Largest Yet

Electronic music titans Empire of the Sun have set the stage for an extraordinary homecoming. The visionary Australian duo, consisting of Luke Steele and...

Everything You Need to Know About Viral Kitchen Gadgets Right Now

TOP RATED PICK 2026 Top Recommended Product ★★★★★ (4.8 out of 5) 🔹 High build quality 🔹 Excellent value for...

What’s new in Gutenberg 24.0? (16 September)

The WordPress open-source community has officially unveiled Gutenberg 24.0, marking another milestone in the project’s biweekly development cycle. This release brings a focused batch...

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!