PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000026. Chiến dịch biệt kích (Commando War)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chiến dịch biệt kích (Commando War)
Commando War
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
There are teams. Team needs minutes of briefing, then independently executes its mission for minutes. Only one team can be briefed at a time, while missions run in parallel. Minimize the time when all teams are finished.
Input
The first line contains . Each of the next lines contains .
Output
Print the minimum time until all teams finish.
Constraints
- .
- for .
Subtasks
- Subtask 1 (20 points): .
- Subtask 2 (30 points): .
- Subtask 3 (50 points): Full constraints.
Examples
Input
3
2 5
3 2
1 4
Output
8
Explanation
The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.