#P6520. [CEOI 2010] mp3player (day2)

[CEOI 2010] mp3player (day2)

Description

There is an MP3 player. If there is no operation for tt consecutive seconds, it will automatically go to sleep. During sleep, any key press will not perform its own function, but will only wake the player up (i.e., end the sleep).

For example, suppose t=5t=5 and the player is currently locked. Then perform the following 4 steps:

  • Press A, wait for 33 seconds.
  • Press B, wait for 55 seconds.
  • Press C, wait for 66 seconds.
  • Press D.

After these operations, the only keys that actually take effect are B and C. Note that the player has already gone to sleep between pressing C and pressing D.

This MP3 player also has two volume control keys + and -, which increase the volume by 1 unit or decrease it by 1 unit, respectively. The volume can only be an integer between 00 and VmaxV_{\max}. That is, if the volume is 00 and you press -, or if the volume is VmaxV_{\max} and you press +, the volume does not change.

At first, you do not know the value of tt, and you want to determine it through an experiment.

The player is sleeping at the beginning. You will start from some volume V1V_1, and after nn operations you obtain volume V2V_2. The exact operations are given. Each operation is of the form +/- CiC_i, meaning that you press + or - at time CiC_i seconds after the experiment starts.

Unfortunately, you also do not know the value of V1V_1. Now, you need to find the maximum possible value of tt that is consistent with the experiment, and output the corresponding V1V_1.

Input Format

The first line contains three integers n,Vmax,V2n, V_{\max}, V_2.

The next nn lines each contain a character xix_i and an integer CiC_i (separated by a space). xix_i is + or -, meaning increasing or decreasing the volume.

CiC_i means that the operation is performed CiC_i seconds after the experiment starts. It is guaranteed that CiC_i is strictly increasing in the input.

Output Format

Output one line with two integers, the values of tt and V1V_1.

If there are multiple possible solutions, output the one with the largest tt. If there are still multiple solutions when tt is maximal, output the one with the largest V1V_1.

If tt can be arbitrarily large, output infinity.

Please note that there is always at least one solution. Because the solution t=0t=0 always exists. In this case, none of the key presses can take effect, so V1=V2V_1=V_2.

6 4 3
- 0
+ 8
+ 9
+ 13
- 19
- 24
5 4
3 10 10
+ 1
+ 2
+ 47
infinity

Hint

Sample Explanation

Sample 1 Explanation

When t=5t=5, the keys behave as: unlock, unlock, +, +, unlock, -.

At this time, for V1{2,3,4}V_1\in \{2,3,4\}, we can obtain V2=3V_2=3. But you should output the largest V1V_1.

When t6t\geq 6, the last two key presses will both work normally, i.e., the volume is decreased twice in a row. Then the result cannot be V2=3V_2=3, so tmax=5t_{\max}=5.

Sample 2 Explanation

When V1=10V_1=10, any tt can satisfy the condition.

Constraints

  • For 40%40\% of the testdata, it is guaranteed that n4000n\le 4000.
  • For 70%70\% of the testdata, it is guaranteed that n×Vmax4×105n\times V_{\max}\le 4\times 10^5.
  • For 100%100\% of the testdata, it is guaranteed that 2n1052\le n\le 10^5, 2Vmax50002\le V_{\max}\le 5000, 0<Ci<2×1090<C_i<2\times 10^9, 0V2Vmax0\le V_2\le V_{\max}, xi{+,-}x_i\in\{\texttt{+}, \texttt{-}\}.

Notes

This problem is translated from CEOI 2010 day 2 T1 mp3player.

The translation copyright belongs to the problem provider

https://www.luogu.com.cn/user/45475

Translated by ChatGPT 5