PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000036. Hoán đổi dung lượng (Swap Space)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hoán đổi dung lượng (Swap Space)
Swap Space
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
There are disk conversion jobs. Job requires at least free space before it starts and afterwards changes free space to . Jobs may be ordered arbitrarily. Find the minimum initial free space needed to execute all jobs.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum initial free space required.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3
10 20
30 10
15 15
Output
20
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.