Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Tasks and Deadlines

#1630
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

You have to process nn 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−fd-f where dd is its deadline and ff is your finishing time. (The starting time is 00, 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 nn: the number of tasks.

After this, there are nn lines that describe the tasks. Each line has two integers aa and dd: the duration and deadline of the task.

Output

Print one integer: the maximum reward.

Constraints
  • 1≤n≤2⋅1051 \le n \le 2 \cdot 10^5
  • 1≤a,d≤1061 \le a,d \le 10^6
Sample Test Cases (1)
Example 1ID: sample-1
Input
3
6 10
8 15
5 12
Expected Output
2
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
3
6 10
8 15
5 12
Expected Output
2