B - Humidifier 1 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 150

問題文

AtCoder社のオフィスには加湿器が 1 つあります。現在は時刻 0 であり、加湿器には水が入っていません。

あなたはこの加湿器にこれから N 回水を追加します。i 回目 (1\leq i \leq N)の水の追加は時刻 T_i に行い、水を V_i リットル追加します。なお、 T_i < T_{i+1} (1 \leq i \leq N-1) を満たすことが保証されます。

ただし、加湿器には穴が空いていて、加湿器に水が入っている間は 1 単位時間につき水が 1 リットル減り続けます。

時刻 T_N に水を追加し終えたとき、加湿器に残っている水の量を求めてください。

制約

  • 1 \leq N \leq 100
  • 1 \leq T_i \leq 100 (1 \leq i \leq N)
  • 1 \leq V_i \leq 100 (1 \leq i \leq N)
  • T_i < T_{i+1} (1 \leq i \leq N-1)
  • 入力は全て整数

入力

入力は以下の形式で標準入力から与えられる。

N
T_1 V_1
T_2 V_2
\vdots
T_N V_N

出力

答えを出力せよ。


入力例 1

4
1 3
3 1
4 4
7 1

出力例 1

3

時系列で以下のように水が追加されます。

  • 時刻 1 : 水を追加する前は 0 リットル入っており、3 リットル追加して加湿器には 3 リットルの水が入っています。
  • 時刻 3 : 水を追加する前は 1 リットル入っており、1 リットル追加して加湿器には 2 リットルの水が入っています。
  • 時刻 4 : 水を追加する前は 1 リットル入っており、4 リットル追加して加湿器には 5 リットルの水が入っています。
  • 時刻 7 : 水を追加する前は 2 リットル入っており、1 リットル追加して加湿器には 3 リットルの水が入っています。

時刻 7 に水を追加し終えたとき、加湿器に残っている水の量は 3 リットルです。よって答えは 3 です。


入力例 2

3
1 8
10 11
21 5

出力例 2

5

入力例 3

10
2 1
22 10
26 17
29 2
45 20
47 32
72 12
75 1
81 31
97 7

出力例 3

57

Score : 150 points

Problem Statement

There is one humidifier in the AtCoder company office. The current time is 0, and the humidifier has no water inside.

You will add water to this humidifier N times. The i-th addition of water (1 \leq i \leq N) takes place at time T_i, and you add V_i liters of water. It is guaranteed that T_i < T_{i+1} for all 1 \leq i \leq N-1.

However, the humidifier has a leak, and as long as there is water inside, the amount of water decreases by 1 liter per unit time.

Find the amount of water remaining in the humidifier immediately after you finish adding water at time T_N.

Constraints

  • 1 \leq N \leq 100
  • 1 \leq T_i \leq 100 (1 \leq i \leq N)
  • 1 \leq V_i \leq 100 (1 \leq i \leq N)
  • T_i < T_{i+1} (1 \leq i \leq N-1)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

N
T_1 V_1
T_2 V_2
\vdots
T_N V_N

Output

Print the answer.


Sample Input 1

4
1 3
3 1
4 4
7 1

Sample Output 1

3

At each point in time, water is added as follows:

  • Time 1: Before adding, the humidifier has 0 liters. After adding 3 liters, it has 3 liters.
  • Time 3: Before adding, it has 1 liter. After adding 1 liter, it has 2 liters total.
  • Time 4: Before adding, it has 1 liter. After adding 4 liters, it has 5 liters total.
  • Time 7: Before adding, it has 2 liters. After adding 1 liter, it has 3 liters total.

After finishing the addition at time 7, the humidifier contains 3 liters. Thus, the answer is 3.


Sample Input 2

3
1 8
10 11
21 5

Sample Output 2

5

Sample Input 3

10
2 1
22 10
26 17
29 2
45 20
47 32
72 12
75 1
81 31
97 7

Sample Output 3

57