PROBLEM DESCRIPTION

Example
Example 1 :
5 5
[1,2,3,4,5]
Example 2 :
5 1
[40,30,20,10,50]
Observation
There is basically two important observation which we can get
Observation
There is basically two important observation which we can get
Observation 1 : Skip the countries which has population less than half of the value of x.
Observation
There is basically two important observation which we can get
Observation 1 : Skip the countries which has population less than half of the value of x.
Why??
Observation
There is basically two important observation which we can get
Observation 1 : Skip the countries which has population less than half of the value of x.
Example :
x= 1000
Country population array ---> [1 ,990]
Observation
Observation 1 : Skip the countries which has population less than half of the value of x.
Example :
x= 1000
Country population array ---> [1 ,990]
If we take the country with population 1 then the vaccine produced on the next day will be 2 and we are wasting 999 vaccines(since vaccine on one day cannot be consumed on the next day)
Observation
Observation 1 : Skip the countries which has population less than half of the value of x.
Example :
x= 1000
Country population array ---> [1 ,990]
Thats not a wise approach.. so what we will do we will provide the vaccine to the country with population 990 and get this country free fully.....!!
Observation
Observation 1 : Skip the countries which has population less than half of the value of x.
Example :
x= 1000
Country population array ---> [1 ,0]
Total vaccines for day 2 is 990*2 = 1960 which we can send to the remaining country
Observation
Observation 1 : Skip the countries which has population less than half of the value of x.
Example :
x= 1000
Country population array ---> [0 ,0]
Hence in 2 days we can cure all of the countries..!!
Observation
In this Optimization we will Cure all the infected person before moving to next country.
Observation 2 :
Observation
We will have two cases
1. when x < arr[i]
2. x >= arr[i]
Observation
Case 1: x < arr[i]
Here we will cure all the infected person thus we will not increment i until x >= arr[i]
Observation
Case 2: x >= arr[i]
Since we have vaccines greater than the infected person we can use the vaccines equal to arr[i].
Observation
Example
12 19 20
x = 4
x < arr[0]
arr[0] = 12 - 4 = 8
And x becomes
x = 8
Observation
arr[0] = 16
x = 8
x < arr[0]
hence at day 2
arr[0] = 16 - 8 = 8
x = 16
Example
12 19 20
x = 4
Observation
Example
12 19 20
x = 4
arr[0] = 16
x = 16
x = arr[0]
hence at day 3
all patients can be cured.
Approach :
#include <bits/stdc++.h>
#define in(n, arr) for (int i = 0; i < n; ++i) cin >> arr[i]
#define out(n, arr) for (int i = 0; i < n; ++i) cout << arr[i] << " "
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out1.txt", "w", stdout);
#endif
long long int t;
cin>>t;
while(t--)
{
int n,x; cin>>n>>x;
int arr[n];
for(int i=0; i<n; i++) cin>>arr[i];
sort(arr, arr+n);
int i=0, tot=0;
while(i<n && 2*arr[i]<x)
{
i++;
tot++;
}
while(i<n)
{
tot++;
if(x<arr[i] && 2*(arr[i]-x) >= arr[i])
{
x = 2*x;
continue;
}
if(arr[i] <= x)
{
x = arr[i];
i++;
}
x = 2*x;
}
cout<<tot<<endl;
}
return 0;
}Still, Have any Doubts???
Still, Have any Doubts???
Comment it You will get a reply
OR
Send your doubt to email provided in description.
Copy of Copy of Copy of Copy of Codechef Cook off
By Chirayu Jain
Copy of Copy of Copy of Copy of Codechef Cook off
- 68