there is a video editorial also available, you can check that out.
[- YouTube](https://vaccine video editorial)
Please someone tell me where i did mistake ?..
for _ in range(int(input())):
l=list(map(int, input().split()))
g=l[0]
p=l[1]
q=sum(l[g+2:]) #number of people before chef’s group
r=q//p #number of days taken for people before to be vaccinated
rem=q%p #number of people left from group before chef’sum
slots=p-rem #number of slots available for chef’s group
if slots>=l[g+1]: #if slots available is more than or equal number of people in chef’s gropu the chef will get vaccinated
print(r+1,r+1) #the day chef get vaccinated is one day more than groups before him
else: #when number of people in chef’s group are more then slots available
w=q+1/p #even the slots are less chef will get vaccinated 1st in his group (min days)
d=int(w)
e=sum(l[g+1:]) #sum of people from chef’s group to last group
t=e/2 #maximum number of days chef will get vaccinated
y=int(t)
max_=0
min_=0
if y<t: #if t is not integer
max_=y+1
else: #if t is integer
max_=y+1
if d<w:
min_=d+1
else:
min_=d
print(min_,max_)
void solve() {
int G, P;
cin >> G >> P;
G–;
vector X(10);
int total = 0;
for (int i = 0; i < 10; i++)
cin >> X[i];
int next = X[G];
for (int i = 9; i > G; i--) {
total += X[i];
}
cout << total / P + 1 << ' ' << (total + next + P - 1) / P << '\n';
}
You can do it too…
void solve() {
int G, P;
cin >> G >> P;
G–;
vector X(10);
int total = 0;
for (int i = 0; i < 10; i++)
cin >> X[i];
total = accumulate(X.begin() + G + 1, X.end(), 0);
cout << total / P + 1 << ' ' << (total + X[G] + P - 1) / P << '\n';
}
#include <bits/stdc++.h>
using namespace std;
int vaccine(int G, int P, int a[])
{
long long sum=0;
int min,max;
for(int i=G-1;i<10;i++)
{
sum += a[i];
}
int r = sum%P;
if(r == 0)
{
min = max = sum/P;
}
else{
min = sum/P;
max = (sum/P) + 1;
}
cout<<min<<" "<<max<<endl;
return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int T,G,P,a[10];
cin>>T;
while(T--)
{
cin>>G>>P;
for(int i=0;i<10;i++)
{
cin>>a[i];
}
vaccine(G,P,a);
}
return 0;
}
Can anyone please help me with this,
The following code passes the sample input(testcase) given in the question but its gets wrong while submitting
I have already defined int for long long i.e line no 11
i think you should start summation of groups which are greater than G. we dont need to add G group value to our sum
cout << (int)ceil(1.0*(s + 1) / p) << " " << (int)ceil(1.0*(s + v[g - 1]) / p)<<endl;
This code is working fine . I don’t the reason because I think ceil auto convert float to int.
Correct me If I am wrong or tell me the reason if you know.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
while(n--)
{
ll x[10];
ll ps[10]={0};
ll g,p;
cin>>g>>p;
for(int i=0;i<10;i++){
cin>>x[i];
}
reverse(x, x + 10);
ps[0]=x[0];
for(int i=1;i<10;i++){
ps[i]=ps[i-1]+x[i];
}
ll res,rt;
ll exc=0,t,remain;
if(g==10)
{
res=ps[0]/p;
remain=ps[0]-p;
ll cnt=0;
if(remain%p!=0){
cnt=1;
}
while(remain>p && remain%p!=0){
remain=remain-p;
cnt++;
}
cout<<res<<" "<<res+cnt<<"\n";
return 0;
}
res=(ps[10-g-1])/p;
remain=ps[10-g-1]%p;
remain+=x[10-g];
ll cnt=0;
while(remain>p && remain%p!=0){
remain=remain-p;
cnt++;
}
cout<<res+1<<" "<<res+cnt+1<<"\n";
}
}
Where i am wrong?any help/edits will be appreciated, Thanks in advance
Me too bro 

#include
using namespace std;
int main()
{
int t,g,p;
cin>>t;
for(int i=0;i<t;i++)
{
int sum=0,mins=0,maxs=0,a[11];
cin>>g>>p;
for(int i=1;i<=10;i++)
{
cin>>a[i];
}
for(int i=g+1;i<=10;i++)
{
sum+=a[i];
}
mins=sum+1;
maxs=sum+a[g];
if(mins%p==0)
{
cout<<(mins)/p;
}
else
{
cout<<((mins)/p)+1;
}
if(maxs%p==0)
{
cout<<" “<<maxs/p<<endl;
}
else
{
cout<<” "<<((maxs/p)+1)<<endl;
}
}
return 0;
}
CAN ANYONE TELL ME WHY IT SHOWS RUNTIME ERROR
@vishal_1827 I also have this same doubt, why do we have to typecast it into (int) , wouldn’t ceil auto-convert float into int?
Hmmm good doubt.
ceil returns the closest integral value as a float or double. But idk why it is not accepted.
Setter’s solution is just an amazing one. Loved that
. I was too thinking of the same logic but unable to implement it.
can anyone help me out with this solution? I am getting a wrong answer
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--)
{
long long g,p,x[10],sum=0;
cin>>g>>p;
for(int i=0;i<10;i++)
{
cin>>x[i];
}
for(int i=g;i<10;i++)
{
sum+=x[i];
}
long long min = sum;
long long max = min;
min = min+1;
max = max+x[g-1];
float l = (float)min/p;
float m = (float)max/p;
cout<<ceil(l)<<" "<<ceil(m)<<endl;
}
return 0;
}
@taran_1407
can you please tell me what is wrong in my code.
my test cases are passing but i am getting wrong ans.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
ll group_no, people;
cin >> group_no >> people;
ll arr[10];
for (ll i = 0; i < 10; i++)
{
cin >> arr[i];
}
ll sum = 0;
for (ll i = group_no - 1; i < 10; i++)
sum = sum + arr[i];
ll sum1 = sum / people;
if (sum <= people)
cout << 1 << " " << 1 << endl;
else if (sum % people == 0)
cout << sum1 << " " << sum1 << endl;
else
cout << sum1 << " " << sum1 + 1 << endl;
}
return 0;
}`
Please don’t try to use float,double etc… these things cause a lot of precision errors.
It will be much better if you try to use integer in place of float or double and you will get the right answer.
Avoid using floating point numbers when precise computation is needed.
Guys,Just try to use to inbuilt functions like pow() etc… and try to give big values you will realise why float won’t work.
It doesn’t work simply because it doesn’t give as the precise answer .
Thus according to my opinion,In CP until and unless specifically asked to use to float or double try to stick with int or long int(according to the constraints).
1
5 2 2 2 2 2 11 11 2 2 2 2
i think your code is not working on this testcase bro