VACCINE3 - Editorial

#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 :pensive::pensive:

#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?

1 Like

Hmmm good doubt.

1 Like

ceil returns the closest integral value as a float or double. But idk why it is not accepted.

1 Like

Setter’s solution is just an amazing one. Loved that :heart: . 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