Skip to content
Programming101
Programming101

Learn everything about programming

  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programming101

Learn everything about programming

HackerEarth Going to office problem solution

YASH PAL, 31 July 2024
In this HackerEarth Going to office problem solution Alice has the following two types of taxis:
Online taxi: It can be booked by using an online application on 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 is Cb, Cm, and Cd that represent 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.
HackerEarth Going to office problem solution

HackerEarth Going to office problem solution.

#include<iostream>
using namespace std;
typedef long long ll;
int main(){
ll d; cin >> d;
ll oc, of, od; cin >> oc >> of >> od;
ll cs, cb, cm, cd; cin >> cs >> cb >> cm >> cd;

ll online = (d <= of)?oc:oc + (od * (d - of));
ll timeClassic = d / cs;
ll classic = cb + timeClassic * cm + cd * d;

if(online <= classic) cout << "Online Taxi" << endl;
else cout << "Classic Taxi" << endl;

}

Second solution

#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const int maxn = 2e5 + 17;

int32_t main(){
ios::sync_with_stdio(0), cin.tie(0);
int d;
cin >> d;
int oc, of, od;
cin >> oc >> of >> od;
int cs, cb, cm, cd;
cin >> cs >> cb >> cm >> cd;
ll fc = 0;
if(d <= of)
fc = oc;
else
fc = oc + (d - of) * od;
ll sc = 0;
sc = (ll) (d + cs - 1) / cs * cm + cb + cd * d;
cerr << fc << ' ' << sc << 'n';
if(fc <= sc)
cout << "Online Taxin";
else
cout << "Classic Taxin";
}
coding problems

Post navigation

Previous post
Next post
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programming101 | WordPress Theme by SuperbThemes