#P1867. Cow Farm Lifepoints and Leveling Simulation

    ID: 15150 Type: Default 1000ms 256MiB

Cow Farm Lifepoints and Leveling Simulation

Cow Farm Lifepoints and Leveling Simulation

Clearman has opened a cow farm in the MC world where he uses insane methods (lava, TNT, etc.) to torture cows for beef, milk, and experience points. He performs a total of n operations. In each operation, he must pay x life points (initial life is 10). Note that before executing each operation, his life is reduced by x; if after the deduction his life is less than or equal to 0, he dies and that operation and all subsequent operations become invalid. Remember, x can be negative (in which case his life is increased by -x), but his life can never exceed 10.

After paying the cost, he gains a experience points (which is always non-negative). At the end of all operations, his total gained experience is used to determine his level and leftover experience according to the following rule:

Starting at level 0, each level-up requires an additional $2^{m}$ experience points where $m$ is the current level. That is, to go from level m to m+1, he needs $2^{m}$ experience points. He repeatedly levels up as long as his remaining experience is at least the required amount.

For example:

  • If Clearman accumulates 15 experience points: $15-1-2-4-8=0$, so his final level is 4 with 0 experience remaining.
  • If Clearman accumulates 39 experience points: $39-1-2-4-8-16=8$, so his final level is 5 with 8 experience remaining.

Your task is to simulate the operations and compute the final level and the leftover experience points.

inputFormat

The first line contains an integer n (the number of operations).

Each of the following n lines contains two space-separated integers: x and a, representing the life point cost (or healing if negative) and the experience gained in that operation, respectively.

outputFormat

Output two integers: the final level and the leftover experience points, separated by a space.

sample

4
1 1
2 2
3 4
1 8
4 0