Subscribe Us

Responsive Advertisement

Advertisement

1345A Alarm Clock codeforces solution in cpp

 

1345A  Alarm Clock codeforces solution in cpp

by ujjal roy



#include<bits/stdc++.h>

using namespace std;

main()

{

   long long int t,a,b,c,d,sum,r,r1,r2;

    cin>>t;

    while(t--)

    {

        cin>>a>>b>>c>>d;

        sum=0;

        sum+=b;

        r=a-b;

        if(r<=0)

        {

            cout<<sum<<endl;


        }

        else

        {

            if(d>=c) cout<<"-1"<<endl;

            else

            {

                r1=c-d;

                r2=r/r1;

                if(r%r1==0)

                {

                    sum+=c*r2;


                }

                else

                {

                    r2++;

                    sum+=c*r2;

                }

                cout<<sum<<endl;

            }

        }

    }




    return 0;

}


Post a Comment

0 Comments