Roy and Alfi reside in two different cities, Roy in city A and Alfi in city B. Roy…
- User
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 T_0 time (in minutes) for Roy to reach station A. The two trains departs in T_1 and T_2 minutes respectively. Average velocities (in km/hr) of trains are V_1 and V_2 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 train optimally.
If its not possible to reach city B, print "-1" instead (without quotes).
Note: If the minimum time is not integral, round the value to the least integer greater than minimum time. Input:
First line will contain integer T, number of test cases.
Second line will contain integers ** T_0, T_1, T_2, V_1, V_2, D ** (their meanings are mentioned in problem statement)
Output:
Print the integral result, minimum time (in minutes) to reach city B in a new line.
Constraints:
1 ≤ T ≤ 10000
1 ≤ T_0,T_1,T_1 ≤ 1000
1 ≤ V_1,V_2 ≤ 500
1 ≤ D ≤ 5000
SAMPLE INPUT 1 5 5 8 100 90 320
SAMPLE OUTPUT 197
Explanation
Roy reaches station A in 5 minutes, First train departs in 5 minutes and second train departs in 8 minutes, he will be able to catch both of them. But he has to make an optimal choice, which train reaches city B in minimum time. For first train \frac{320}{100} =; 3.2; hrs; = 192 minutes. Total time for first train, 5+192 = 197 minutes
For second train \frac{320}{90} = 3.555556; hrs; = 213.33336 minutes. Least integer greater than 213.33336; is ;214. Total time for second train 214+8 = 222 minutes. So optimal choice is to take first train, and hence the minimum time is 197 minutes.
Assistant
pythonimport math import sys def main(): input = sys.stdin.read().split() idx = 0 T = int(input[idx]) idx +=1 for _ in range(T): T0 = int(input[idx]) T1 = int(input[idx+1]) T2 = int(input[idx+2]) V1 = int(input[idx+3]) V2 = int(input[idx+4]) D = int(input[idx+5]) idx +=6 possible = [] # Check first train if T0 <= T1: travel = (D * 60) / V1 total = T1 + math.ceil(travel) possible.append(total) # Check second train if T0 <= T2: travel = (D * 60) / V2 total = T2 + math.ceil(travel) possible.append(total) # Determine result if not possible: print(-1) else: print(int(min(possible))) if __name__ == "__main__": main()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.