The MP3 Player

Time limit1sMemory limit128 MB

Summary
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 TT 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 T=5T = 5 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 TT, 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 00 and VmaxV_{max}. Pressing + while the volume is VmaxV_{max}, or - while it is 00, leaves the volume unchanged.

Georg does not know TT and wants to find it experimentally. Starting from a locked keyboard, he pressed a sequence of NN keys, each + or -, and then read the final volume from the display. He forgot to note the volume before his first keypress. Let V1V_1 denote that unknown initial volume and V2V_2 the known final volume.

You are given V2V_2 together with, for each keypress, its type (+ or -) and the number of seconds from the start of the experiment. Find the largest integer TT that is consistent with this outcome.

Input

The first line contains three space-separated integers NN, VmaxV_{max}, and V2V_2 (0≤V2≤Vmax0 \le V_2 \le V_{max}).

Each of the next NN lines describes one keypress: the character + or -, a space, and an integer CiC_i (0≤Ci≤2⋅1090 \le C_i \le 2 \cdot 10^9) 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. Ci<Ci+1C_i < C_{i+1} for every 1≤i<N1 \le i < N.

Output

If TT can be arbitrarily large, print a single line containing the word infinity.

Otherwise, print a single line with two integers TT and V1V_1 separated by one space, such that performing the experiment with lock time TT starting from volume V1V_1 yields the final volume V2V_2. If several values of TT are possible, print the largest one; if several values of V1V_1 still remain, print the largest one.

At least one answer always exists: when T=0T = 0 no key ever performs its function, so V1=V2V_1 = V_2 is always valid.

Constraints

2≤N≤1000002 \le N \le 100000 and 2≤Vmax≤50002 \le V_{max} \le 5000.

Examples2

  1. Example 1

    Input
    6 4 3
    - 0
    + 8
    + 9
    + 13
    - 19
    - 24
    
    Expected output
    5 4
    
  2. Example 2

    Input
    3 10 10
    + 1
    + 2
    + 47
    
    Expected output
    infinity