#GD0000064. Tái sử dụng máy trạm (Workstations)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tái sử dụng máy trạm (Workstations)
Workstations
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
A lab has enough workstations. Researcher arrives at time and uses a workstation continuously for minutes. A workstation remains unlocked for minutes after use and then locks if idle. Busy workstations cannot be shared, and all machines are initially locked. Maximize the number of unlock operations saved compared with unlocking a workstation for every researcher.
Input
The first line has . The next lines have , the arrival time and usage duration of researcher .
Output
Print the maximum number of unlock operations that can be saved.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
3 5
1 3
4 2
9 1
Output
2
Explanation
The first person finishes at time ; the second arrives at and reuses that machine. The second finishes at , and the third arrives at , within the -minute grace period. Two unlock operations are saved.