Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone

Learn everything about programming

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

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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