P26967 [AtCoder] Capture
省选
题目描述

Problem Description

In a long, narrow forest stretching east-west, there are $ N $ creatures living. Hereafter, we will refer to the point $ p $ meters from the west end of the forest as point $ p $. The $ i $-th creature from the west (where $1 \leq i \leq N$) is located at point $ x_i $ and can be sold for $ s_i $ yen when captured.

You choose integers $ L $ and $ R $ ($L \leq R$) and cast a net from point $ L $ to point $ R $, inclusive, covering the range $ [L, R] $. All creatures within this range will be captured. However, the net costs $ R - L $ yen, and your profit will be the total sum of $ s_i $ for all captured creatures minus $ R - L $ yen.

What is the maximum profit you can obtain by casting the net once?

Input Format

The input is given from the standard input in the following format:

$ N $ $ x_1 $ $ s_1 $ $ x_2 $ $ s_2 $ $ : $ $ x_N $ $ s_N $

Output Format

When the maximum profit obtained is $ X $ yen, output the value of $ X $.

Sample Input and Output

Sample Input #1

5
10 20
40 50
60 30
70 40
90 10

Sample Output #1

90

Sample Input #2

5
10 2
40 5
60 3
70 4
90 1

Sample Output #2

5

Sample Input #3

4
1 100
3 200
999999999999999 150
1000000000000000 150

Sample Output #3

299

Notes/Hints

Constraints

  • $1 \leq N \leq 2 \times 10^5$
  • $1 \leq x_1 < x_2 < ... < x_N \leq 10^{15}$
  • $1 \leq s_i \leq 10^9$
  • All input values are integers.

Sample Explanation 1

Casting the net in the range $ [L = 40, R = 70] $ can capture the 2nd, 3rd, and 4th creatures from the west, yielding a profit of $ s_2 + s_3 + s_4 - (R - L) = 90 $ yen. It is not possible to obtain a profit of 91 yen or more.

Sample Explanation 2

The creatures are in the same positions as in Input Example 1, but their selling prices have significantly decreased, so aiming for more than two is not advisable. Casting the net in the range $ [L = 40, R = 40] $ yields a profit of $ s_2 - (R - L) = 5 $ yen, which is the maximum.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 10 20 40 50 60 30 70 40 90 10
样例输出
90