Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Roy and Trains problem solution

YASH PAL, 31 July 2024
In this HackeEarth Roy and Trains problem solution Roy and Alfi reside in two different cities, Roy in city A and Alfi in city B. Roy wishes to meet her in city B.
There are two trains available from city A to city B. Roy is on his way to station A (Railway station of city A). It will take To time (in minutes) for Roy to reach station A. The two trains depart in T1 and T2 minutes respectively. The average velocities (in km/hr) of trains are V1 and V2 respectively. We know the distance D (in km) between city A and city B. Roy wants to know the minimum time (in minutes) to reach city B if he chooses to train optimally. If it’s not possible to reach city B, print “-1” instead (without quotes).
HackerEarth Roy and Trains problem solution

HackerEarth Roy and Trains problem solution.

def roy_and_trains():
for t in xrange(input()):
t0,t1,t2,v1,v2,d = map(int,raw_input().split())
temp = float(d)/v1
temp *= 60
temp2 = int(temp)
if temp > temp2:
temp2 += 1
total1 = t1 + temp2
temp = float(d)/v2
temp *= 60
temp2 = int(temp)
if temp > temp2:
temp2 += 1
total2 = t2 + temp2
if t0 > t1 and t0 > t2:
print "-1"
elif t0 <= t1 and t0 > t2:
print total1
elif t0 > t1 and t0 <= t2:
print total2
else:
print min(total1,total2)
roy_and_trains()
coding problems solutions

Post navigation

Previous post
Next post

Related website

The Computer Science

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