#P5485. [JLOI2010] 铁人双项比赛

[JLOI2010] 铁人双项比赛

Description

The Ironman Duathlon is a traditional sports event of Jilin Institute of Education. The race consists of long-distance running and cycling. Each contestant must first complete a kk-kilometer run, and then complete an rr-kilometer bike ride to reach the finish line. Different contestants are good at different events: some are better at running, while others are better at cycling. If the total distance s=k+rs=k+r is fixed, then the larger kk is, the more advantageous it is for contestants who are good at running; the smaller kk is, the more advantageous it is for contestants who are good at cycling.

Now you are given the total distance ss, as well as each contestant’s average speed for running and cycling. Please find the values of kk and rr that are the most favorable for a specified contestant. “Most favorable” means that after choosing this kk and rr, the contestant can win the championship, and the lead over the second place is as large as possible.

Input Format

Your program reads input from a file.
The first line contains two positive integers ss and nn. ss is the total distance (in kilometers, s231s\leq 2^{31}), and nn is the total number of contestants (2n1002\leq n\leq 100).
The next nn lines each contain two real numbers, representing each contestant’s average running speed and average cycling speed (in kilometers per hour).
The nn-th contestant is the specified contestant. Your task is to find the most favorable kk and rr for them.

Output Format

Your program should output three numbers k,r,tk,r,t, representing the most favorable kk and rr for contestant nn (floating-point numbers, rounded to 22 decimal places), and the maximum number of seconds by which contestant nn can lead the second place under this choice of kk and rr (rounded to an integer). If another contestant ties with them for first place, then t=0t=0. If contestant nn cannot win no matter what kk and rr are chosen, output NO.

100 3
10.0 40.0
20.0 30.0
15.0 35.0
14.29 85.71 612

Hint

Translated by ChatGPT 5