Header Ad

HackerEarth Roy and Trains problem solution

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()

Post a Comment

0 Comments