Need help(task 22)

Back to Problem Solutions forum

DunderMifflin     2016-08-26 06:49:01
User avatar

// // main.cpp // Printers // // Created by Vishal Sabasu on 25/08/16. // //

include<iostream>

include<iomanip>

using namespace std;

int main() { int t; long int x,y,n,m; long int time[300]; cin>>t;

for(int i=0;i<t;i++)
{
    cin>>x>>y>>n;
    if(x==y)
    {

        m=x*(n/2);
        if(n%2!=0)
            m=m+x;

        time[i]=m;
    }
   else if(x<y)
    {
        if(x*n<y)
            time[i]=x*n;
        else if(x*n>y)
        {
            long int z=1;
            long int l=0;
            long int v=0;
            while(1)
            {
                l=(z*x)/y;
                v=l+z;
                if(v==n)
                {
                    time[i]=x*z;
                    break;

                }
                else if(v>n)
                {


                    time[i]=x*z+(x*(v-n));
                    break;


                }

                z++;



            }



        }

    }
    else if(y<x)
    {
        if(y*n<x)
            time[i]=y*n;
        else if(y*n>x)
        {

            long int z=1;
            long int l=0;
            long int v=0;
            while(1)
            {
                l=(z*y)/x;
                v=l+z;
                if(v==n)
                {
                    time[i]=y*z;
                    break;
                }
                else if(v>n)
                {


                    time[i]=y*z+(y*(v-n));
                    break;


                }


                z++;



            }

        }
    }



}

for(int i=0;i<t;i++)
    cout<<time[i]<<" ";

return 0;

}

EXPECTED ANSWER VS MINE

360534957 294352395 342703760 242938734 97922940 16474632 52776161 135828692 212586792 469641660 266259171 227317762 61432832 83400478 25745091 325613194 202214516 283971528 345208400 ( V S ) 360535228 294354249 342703760 242938734 97922940 16474632 52776161 135828692 212586792 488607249 266259171 236545029 61432832 83400478 27864984 325613195 202214516 283975898 345208400

I don't know which test cases are going wrong.Please help if possible.

Quandray     2016-08-26 07:18:17
User avatar

At least the first and second are wrong. I suggest you try your code with some input containing smaller numbers, maybe

1
3 5 10
DunderMifflin     2016-08-26 07:30:53
User avatar

The answer for the above test case, 20 or 21 ?

Quandray     2016-08-26 10:16:18
User avatar

6 on fast printer taking 18 seconds and 4 on slow printer taking 20 seconds

DunderMifflin     2016-08-26 12:07:34
User avatar

Solved it,thanks a lot. :)

Please login and solve 5 problems to be able to post at forum