#2011. [CEOI2010] Mp3 Player

[CEOI2010] Mp3 Player

题目描述

Georg 有个 MP3 Player,没有任何操作 tt 秒钟就会锁定,这时按下任意一个键就会变回没锁定的状态,但不会改变频道。只有在没锁定的状态下按键才有可能改变频道。MP3 的频道为 0vmax0 \sim v_{max},如果现在是 xx 频道,若 x<vmaxx < v_{max},在无锁状态下按 +xx 就会加 11。若 x>0x>0,在无锁状态下按 -xx 就会减 11。Georg 忘记了 MP3 的 tt 是多少。他想通过一段操作试验一下。然后他就写下他的操作顺序和最后停留的频道 v2v_2,然后就给你了,你要求的是 tt 的最大值和 tt 在这个值的情况下,第一个操作前的频道 v1v_1 的最大可能数。

输入格式

第一行:n,vmax,v2n,v_{max},v_2nn 表示 Georg 操作了 nn 次;

以下 nn 行,每行第一个为字符 cc,第二个为数字 tit_i,表示 Georg 在 tit_i 秒按下了 cc 键。

输出格式

输出 tt 的最大值和 tt 在这个值的情况下,第一个操作前的频道 v1v_1 的最大可能数。

tt 为无限大时经过这段操作最后能停在 v2v_2,则输出 infinity

6 4 3
- 0
+ 8
+ 9
+ 13
- 19
- 24
5 4

样例说明 1

For t=5t=5 the keys perform the following actions: unlock, unlock, +, +, unlock, -. For any we would get v2=3v_2 = 3. Note that the output contains the largest possible v1v_1. For the last two keystrokes will both be active, hence it will be impossible to have v2=3v_2=3.

3 10 10
+ 1
+ 2
+ 47
infinity

样例说明 2

If v1=10v_1 = 10 then for any tt we'll have v2=10v_2 = 10.

数据规模与约定

对于 40%40\% 的数据,n4×103n \leq 4\times10^3

对于 70%70\% 的数据,n×vmax4×105n \times v_{max}\leq 4\times 10^5

对于 100%100\% 的数据,2n1052\leq n\leq 10^52vmax5×1032\leq v_{max}\leq 5\times10^30<ci<2×1090 < c_i < 2\times 10^90v2vmax0\leq v_2 \leq v_{max}xi{+,-}x_i\in\{\texttt{+}, \texttt{-} \}