Duathlon
InterviewTime limit1sMemory limit128 MB
Given each competitor's running and cycling speeds and a fixed total distance, choose the run and cycle legs so the last competitor wins by the largest margin, or report that no such split exists.
- Level
Medium6 of 10
- Topics
- Geometry, Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
A duathlon is a race in which each competitor first runs km and then cycles km. competitors have entered, and every competitor has a different running speed and cycling speed. One of them has bribed the organizers so that they will choose and (with the total distance fixed) to let him win by the largest possible margin. Determine whether this is possible and, if so, find the values of and .
Input
The first line contains an integer , the total distance of the race in km, so that . The second line contains an integer , the number of competitors. Each of the next lines contains two real numbers: the running speed and cycling speed (in km/h) of one competitor. The last of these lines is the competitor who bribed the organizers (the cheater); the other are the honest competitors he must beat. You may assume does not exceed km and does not exceed .
Output
If the race can be fixed as described, print a single line of exactly the form The cheater can win by <S> seconds with r = <R>km and k = <K>km., where <S> is the winning margin in seconds rounded to the nearest whole second and <R> and <K> are the running and cycling distances in km rounded to two decimal places (there is no space between a number and km). If it is not possible for the cheater to win, print The cheater cannot win..