This page is still under construction.

Parts of this page are still being built. What you see may change.

Duathlon

Interview

Time limit1sMemory limit128 MB

Summary
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 rr km and then cycles kk km. nn 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 rr and kk (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 rr and kk.

Input

The first line contains an integer tt, the total distance of the race in km, so that r+k=tr + k = t. The second line contains an integer nn, the number of competitors. Each of the next nn lines contains two real numbers: the running speed and cycling speed (in km/h) of one competitor. The last of these nn lines is the competitor who bribed the organizers (the cheater); the other n−1n-1 are the honest competitors he must beat. You may assume tt does not exceed 100100 km and nn does not exceed 2020.

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..

Examples2

  1. Example 1

    Input
    100
    3
    10.0 40.0
    20.0 30.0
    15.0 35.0
    
    Expected output
    The cheater can win by 612 seconds with r = 14.29km and k = 85.71km.
    
  2. Example 2

    Input
    100
    3
    10.0 40.0
    20.0 30.0
    15.0 25.0
    
    Expected output
    The cheater cannot win.