408008: GYM102961 V Tasks and Deadlines

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

V. Tasks and Deadlinestime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

You have to process $$$n$$$ tasks. Each task has a duration and a deadline, and you will process the tasks in some order one after another. Your reward for a task is $$$d−f$$$ where $$$d$$$ is its deadline and $$$f$$$ is your finishing time. (The starting time is $$$0$$$, and you have to process all tasks even if a task would yield negative reward.)

What is your maximum reward if you act optimally?

Input

The first input line has an integer $$$n$$$: the number of tasks.

After this, there are $$$n$$$ lines that describe the tasks. Each line has two integers $$$a$$$ and $$$d$$$: the duration and deadline of the task.

Constraints:

  • $$$1 \le n \le 2\cdot 10^5$$$
  • $$$1 \le a,d \le 10^6$$$
Output

Print one integer: the maximum reward.

ExampleInput
3
6 10
8 15
5 12
Output
2

加入题单

算法标签: