You are given two variants of route, one with length equal to sqrt(2) * N and maximal velocity V_1, and another with length equal to 2 \cdot N and maximal velocity V_2. You have to find which route will use less time.
QUICK EXPLANATION:
S = v * t, so just calculate time of both routes.
The complexity is O(1) for one testcase, O(T) in total.
EXPLANATION:
Time of the first route is T_1 = \frac{sqrt(2) * N}{ V_1}. Time of the second T_2 = \frac{2 * N}{V_2}.
So, we can compare this fractional numbers, or, alternatively, make some transitions and get that:
T_1 ? T_2
V_2 * sqrt(2) ? V_1 * 2
V_2 ? V_1 * sqrt(2)
So, the first route is faster if V_2 < V_1 * sqrt(2). Why the times couldn’t be equal? Imagine that V_2 = V_1 * sqrt(2). V_2 is integer, while V_1 * sqrt(2) is irrational. Obviously, they can’t be equal.
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.