Doctor Chef | DRCHEF | CodeChef
Chef is multi-talented. He has developed a cure for coronavirus called COVAC-19. Now that everyone in the world is infected, it is time to distribute it throughout the world efficiently to wipe out coronavirus from the Earth. Chef just cooks the cure, you are his distribution manager.
In the world, there are countries (numbered through ) with populations . Each cure can be used to cure one infected person once. Due to lockdown rules, you may only deliver cures to one country per day, but you may choose that country arbitrarily and independently on each day. Days are numbered by positive integers. On day , Chef has cures ready. On each subsequent day, Chef can supply twice the number of cures that were delivered (i.e. people that were cured) on the previous day. Chef cannot supply leftovers from the previous or any earlier day, as the cures expire in a day. The number of cures delivered to some country on someday cannot exceed the number of infected people it currently has, either.
However, coronavirus is not giving up so easily. It can infect a cured person that comes in contact with an infected person again ― formally, it means that the number of infected people in a country doubles at the end of each day, i.e. after the cures for this day are used (obviously up to the population of that country).
Find the minimum number of days needed to make the world corona-free.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers .
Output
For each test case, print a single line containing one integer ― the minimum number of days.
Constraints
- for each valid
- the sum of over all test cases does not exceed
Subtasks
Subtask #1 (20 points):
Subtask #2 (80 points): original constraints
Solution (C++)
#include
using namespace std;
#define mod 1000000007
#define ll long long int
ll find_lowerBound(vector< ll>vec,ll x)
{
vector<ll>::iterator it = lower_bound(vec.begin(), vec.end(), x);
ll lowerb = it - vec.begin();
return lowerb;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
ll size, x, sum=0;
cin>>size >> x;
vector<>vec(size);
for(int i=0; i < size; i++)
{
cin >>vec[i];
}
sort(vec.begin(), vec.end());
ll low=find_lowerBound(vec,x);
for(int i=low; i
{
if(x<vec[i])
{
while(x<vec[i])
{
x = x*2;
sum++;
}
sum++;
}
else
sum++;
x = 2*vec[i];
}
ll count =low+sum;
if(low != 0)
{
sum = 0;
low--;
for(int i=low; i<size; i++)
{
if(x < vec[i])
{
while(x<vec[i])
{
x = 2*x;
sum++;
}
sum++;
}
else
sum++;
x = 2*vec[i];
}
if(sum+low<count)
cout<<sum+low<< endl;
else
cout<<count<< endl;
}
else
cout<<count<<endl;
}
return 0;
}
100 Best Headphone under 600

Comments
Post a Comment