#P4343. Determine the Possible Threshold of Code Lines
Determine the Possible Threshold of Code Lines
Determine the Possible Threshold of Code Lines
The Auto Problem Solver works in a very peculiar way. It instantly obtains the correct solution and then writes code in a series of one‐second intervals. In each second, one of the following two events happens:
- The machine writes \(x\) lines of code.
- The machine is in a bad mood and deletes \(y\) lines of code. (If \(y\) is greater than the current number of code lines, then all code is deleted.)
An online judge (OJ) uses a fixed positive integer threshold \(n\) such that at the end of any second if the accumulated number of code lines reaches or exceeds \(n\), the OJ immediately submits the file (and the submission is accepted), discards the current code, and the machine starts a new file for the next problem.
After running the Auto Problem Solver for one day, the log of the machine’s activity was recorded. Although all the logs of the writing and deletion events were kept, the actual threshold \(n\) was not recorded. However, based on his rank on the OJ, the operator SHTSC knows that the machine submitted exactly \(k\) problems that day. Your task is to determine the smallest and largest possible values of \(n\) that are consistent with the given log.
Note: In case the largest possible value of \(n\) is unbounded, output Infinity
as the maximum.
inputFormat
The first line contains two integers \(m\) and \(k\) \((1 \le m \le 10^5)\), representing the number of log events and the number of problems submitted, respectively.
Then follow \(m\) lines. Each of these lines contains two integers. The first integer is either 1
or 2
indicating the type of event. If the integer is 1
, the second integer \(x\) \((1 \le x \le 10^5)\) denotes that \(x\) lines of code were written. If it is 2
, then the second integer \(y\) \((1 \le y \le 10^5)\) denotes that \(y\) lines of code were deleted.
It is guaranteed that the operations are valid and the sum of all \(x\) values does not exceed \(10^9\).
outputFormat
Output two space‐separated values: the minimum possible \(n\) and the maximum possible \(n\) that yield exactly \(k\) submissions when simulating the log as described. If the maximum possible \(n\) is unbounded, output Infinity
instead of a number.
sample
3 2
1 3
1 2
1 1
2 3
</p>