Water Volume

Time limit: 1000 ms
Memory limit: 256 MB

Alex has a glass that initially contains some quantity of water (it's possible that the glass is empty). He performs NN operations of two types:

  1. Pour xx ml (millilitres) of water in the glass
  2. Drink xx ml of water from the glass

Alex writes down on a piece of paper the initial quantity of water. After each operation he writes down another number, representing the new volume of water in the glass. In total there will be N+1N+1 numbers.

You know that the lowest number written by Alex is 00. Find the largest one.

Standard input

The first line contains a single integer NN, the number of operations.

Each of the next NN lines contains two integers tt and xx. If t=0t = 0 Alex pours xx ml in the glass, if t=1t = 1 he drinks xx ml.

Standard output

Print the answer, expressed in ml, on the first line.

Constraints and notes

  • 1N10001 \leq N \leq 1\,000
  • 1xi10001 \leq x_i \leq 1\,000

InputOutputExplanation
4
0 1
0 1
0 1
1 3
3

The glass initially has 00ml of water. The maximum value is obtained after the first 33 operations.

2
1 15
1 24
39

The glass initially has 3939ml of water, and this is also the maximum value.

Authenticate to use the workspace

Log In
Sign Up
Forgot Password?
or connect with