eolymp
bolt
Try our new interface for solving problems
Məsələlər

Traffic Jam

Traffic Jam

The most annoying thing in Moscow traffic jams is that drivers constantly try to suddenly change lanes in order to move faster. In this problem you'll have to find out whether this is a reasonable strategy or not. We'll study a relatively simple mathematical model of a traffic jam. Assume that there's an \textit{N}-lane road, lanes numbered from 1 to \textit{N}, and \textit{i}^th lane is moving with speed \textit{b}_i+\textit{a}_i·\textit{sin}(\textit{t}+δ_i) at the moment \textit{t}. It is always true that \textit{b}_i > \textit{a}_i, i.e., the speed of movement is always positive. You can change the lane you're in at any time, it takes \textit{c}·|x-\textit{y}| to change from \textit{x}^th lane to \textit{y}^th. We'll assume that you're not moving forward during that period. Determine the time you need to travel the distance of \textit{d}, and the method of achieving that time. You're starting at the moment 0 at lane 1, you may finish at any lane. \InputFile The first line of input contains two integers \textit{N} and \textit{d} and a floating-point number \textit{c}, 1 ≤ \textit{N} ≤ 5, 1 ≤ \textit{d} ≤ 1000, 0.001 ≤ \textit{c} ≤ 1000. The next \textit{N} lines describe lanes, each containing two integers \textit{a}_i and \textit{b}_i and a floating-point number δ_i, 0 ≤ \textit{a}_i < \textit{b}_i ≤ 100, 0 ≤δ_i < 2π. \OutputFile On the first line of output print the minimal time required to travel the distance of \textit{d}. On the second line of output print the number \textit{K} of lane changes required to do that. \textit{K} should not be more than 10^6, it is guaranteed that there always exists an optimal strategy requiring not more than 10^6 lane changes. On the next \textit{K} lines print the changes themselves, each line should contain the new lane number and the time when the change is started. The changes should be printed in chronological order. If there're many possible schedules, output any. Output all the floating-point numbers with maximal precision possible. Your solution will be considered correct if verifying your schedule doesn't lead to discrepancies of more than 10^\{-6\} (in checking the total distance traveled, in checking that lane changes are non-overlapping, etc), so it's better for you to output at least 10-12 digits after the decimal point in each floating-point number.
Zaman məhdudiyyəti 2 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
1 100 0.5
4 5 0
Çıxış verilənləri #1
19.71726232777025
0
Müəllif Пётр Митричев
Mənbə Зимняя школа, Харьков 2011, День 8