Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

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

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

Topics we are covering

Toggle
  • HackerEarth Going to office problem solution.
    • Second 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

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • 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
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes