Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
      • Data Structures Solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Going to office problem solution

YASH PAL, 31 July 202413 February 2026
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 solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes