eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

The MP3 Player

The MP3 Player

Georg's new MP3 player has many interesting features, one of them being the key lock. All the keys are locked after more than \textbf{T} seconds of inactivity. After the key lock is engaged, no key performs its original function, but if any key is pressed, the key lock is disengaged. For example, assume that \textbf{T = 5} and the player is currently locked. Georg presses the key \textbf{A}, waits for \textbf{3} seconds, presses the key \textbf{B}, waits for \textbf{5} seconds, presses \textbf{C}, waits for \textbf{6} seconds, and presses \textbf{D}. In this case only the keys \textbf{B} and\textbf{C} perform their regular functions. Note that the keys became locked between \textbf{C} and \textbf{D} was pressed. Sound level of the MP3 player is controlled by the \textbf{+} and \textbf{-} keys, increasing and decreasing volume by \textbf{1} unit respectively. The sound level is an integer between \textbf{0} and \textbf{V_max}. Pressing the \textbf{+} key at volume \textbf{V_max} or pressing the \textbf{-}key at volume \textbf{0} leaves the volume unchanged. Georg does not know the value of \textbf{T}. He wanted to find it by an experiment. Starting with a locked keyboard, he pressed a sequence of \textbf{N} \textbf{+} and \textbf{-} keys. At the end of the experiment Georg read the final volume from the player's display. Unfortunately, he forgot to note the volume before his first keypress. For the purpose of this task, the unknown initial volume will be denoted \textbf{V_1} and the known final volume will be denoted \textbf{V_2}. You are given the value \textbf{V_2} and a list of keystrokes in the order in which Georg made them. For each key, you are given the type of the key (\textbf{+} or \textbf{-}) and the number of seconds from the beginning of the experiment to the moment when the key was pressed. The task is to find the largest possible integer value of \textbf{T} which is consistent with the outcome of the experiment. \InputFile The first line of the input contains three space-separated integers \textbf{N}, \textbf{V_max} and \textbf{V_2} (\textbf{0} ≤ \textbf{V_2} ≤ \textbf{V_max}). Each of the next \textbf{N} lines contains a description of one key in the sequence: a character \textbf{+} or \textbf{-}, a space and an integer \textbf{C_i} (\textbf{0} ≤ \textbf{C_i}≤ \textbf{2·10^9}), the number of seconds from the beginning of the experiment. You may assume that the keypresses are in sorted order and that all times are distinct (i.e., \textbf{C_i} < \textbf{C_\{i+1\}} for all \textbf{1} ≤ \textbf{i} < \textbf{N}). \textbf{Constraints} You may assume that \textbf{2} ≤ \textbf{N} ≤ \textbf{100000} and \textbf{2} ≤ \textbf{V_max} ≤ \textbf{5000}. In test cases worth \textbf{40} points \textbf{N} ≤ \textbf{4000}. In test cases worth \textbf{70} points \textbf{N·V_max} ≤ \textbf{400000}. \OutputFile If \textbf{T} can be arbitrarily large, output a single line containing the word "\textbf{infinity}" (quotes for clarity). Otherwise, output a single line containing two integers \textbf{T} and \textbf{V_1} separated by a single space. The values must be such that carrying out the experiment with locking time \textbf{T} starting at volume \textbf{V_1} gives the final volume \textbf{V_2}. If there are multiple possible answers, output the one with the largest \textbf{T}; if there are still multiple possible answers, output the one with the largest \textbf{V_1}. (Note that at least one solution always exists: for \textbf{T = 0} none of the keys performs its action, so it suffices to take \textbf{V_1 = V_2}.)
Лимит времени 1 секунда
Лимит использования памяти 256 MiB
Входные данные #1
6 4 3
- 0
+ 8
+ 9
+ 13
- 19
- 24
Выходные данные #1
5 4
Автор Peter Fulla