The MP3 Player
Time limit1sMemory limit128 MB
Determine the largest lock timeout T and matching initial volume V1 so that a sequence of timed +/- presses on a lockable MP3 player ends at the given volume V2.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Simulation
- Solved
- No attempts yet
Problem
Georg's new MP3 player has a key-lock feature. The keyboard locks automatically after more than seconds without any keypress. While the keyboard is locked, no key performs its normal function; the next keypress only unlocks the keyboard and does nothing else. Every keypress — whether it unlocks the keyboard or performs its function — resets the inactivity timer.
For example, suppose and the keyboard is currently locked. Georg presses key A, waits 3 seconds, presses B, waits 5 seconds, presses C, waits 6 seconds, and presses D. Only B and C perform their normal function: the first press A merely unlocks the keyboard, and the 6-second gap before D exceeds , so the keyboard relocks and D only unlocks it again.
The volume is controlled by the + and - keys, which raise and lower it by one unit respectively. The volume is an integer between and . Pressing + while the volume is , or - while it is , leaves the volume unchanged.
Georg does not know and wants to find it experimentally. Starting from a locked keyboard, he pressed a sequence of keys, each + or -, and then read the final volume from the display. He forgot to note the volume before his first keypress. Let denote that unknown initial volume and the known final volume.
You are given together with, for each keypress, its type (+ or -) and the number of seconds from the start of the experiment. Find the largest integer that is consistent with this outcome.
Input
The first line contains three space-separated integers , , and ().
Each of the next lines describes one keypress: the character + or -, a space, and an integer () giving the time in seconds from the start of the experiment. The keypresses are listed in chronological order and all times are distinct, i.e. for every .
Output
If can be arbitrarily large, print a single line containing the word infinity.
Otherwise, print a single line with two integers and separated by one space, such that performing the experiment with lock time starting from volume yields the final volume . If several values of are possible, print the largest one; if several values of still remain, print the largest one.
At least one answer always exists: when no key ever performs its function, so is always valid.
Constraints
and .