Going to office

Alice has the following two types of taxis:
  • Online taxi: It can be booked by using an online application from phones 
  • Classic taxi: It can be booked anywhere on the road

The online taxis cost Oc for the first Of km and Od for every km afterward. The classic taxis travel at a speed of Cs km per minute. The cost of classic taxis are CbCm, and Cd that represents the base fare, cost for every minute that is spent in the taxi, and cost for each kilometer that you ride.

You are going to the office from your home. Your task is to minimize the cost that you are required to pay. The distance from your home to the office is D. You are required to select whether you want to use online or classic taxis to go to your office. If both the taxis cost the same, then you must use an online taxi.

Example:

Input:  d=13, oc=6, of=7 , od=4,   cs= 4, cb=2, cm=1, cd=2
Output: Online Taxi

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    long long d = 13;
    long long oc = 6of = 7od = 4;
    long long cs = 4cb = 2cm = 1cd = 2;

    long long cost1 = 0;
    long long cost2 = 0;
    cost1 = oc + (d - of) * od;
    cost2 = cb + d * cd + (d / cs) * cm;
    if (cost1 <= cost2)
        cout << "Online Taxi\n";
    else
        cout << "Classic Taxi\n";
    return 0;
}


No comments:

Post a Comment