Georg 有个 MP3 Player,没有任何操作 秒钟就会锁定,这时按下任意一个键就会变回没锁定的状态,但不会改变频道。只有在没锁定的状态下按键才有可能改变频道。MP3 的频道为 ,如果现在是 频道,若 ,在无锁状态下按 +, 就会加 。若 ,在无锁状态下按 -, 就会减 。Georg 忘记了 MP3 的 是多少。他想通过一段操作试验一下。然后他就写下他的操作顺序和最后停留的频道 ,然后就给你了,你要求的是 的最大值和 在这个值的情况下,第一个操作前的频道 的最大可能数。
+
-
第一行:。 表示 Georg 操作了 次;
以下 行,每行第一个为字符 ,第二个为数字 ,表示 Georg 在 秒按下了 键。
输出 的最大值和 在这个值的情况下,第一个操作前的频道 的最大可能数。
若 为无限大时经过这段操作最后能停在 ,则输出 infinity。
infinity
6 4 3 - 0 + 8 + 9 + 13 - 19 - 24
5 4
For the keys perform the following actions: unlock, unlock, +, +, unlock, -. For any we would get . Note that the output contains the largest possible . For the last two keystrokes will both be active, hence it will be impossible to have .
unlock, unlock, +, +, unlock, -
3 10 10 + 1 + 2 + 47
If then for any we'll have .
对于 的数据,。
对于 的数据,,,,,。