#FT0000197. Thời gian hoạt động tối thiểu (Minimum Time to Complete All Tasks)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thời gian hoạt động tối thiểu (Minimum Time to Complete All Tasks)
Minimum Time to Complete All Tasks
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A computer can process an unlimited number of tasks simultaneously while it is on. There are tasks. Task may use only integer time slots in its inclusive interval and needs at least active time slots. Its active slots need not be consecutive.
You may decide for each integer time slot whether the computer is on. A slot in which the computer is on can simultaneously count towards every task whose interval contains that slot, but it contributes only one unit to the total on-time.
Find the minimum number of time slots for which the computer must be on to complete all tasks.
Input
- The first line contains , the number of tasks.
- Each of the next lines contains three integers : the inclusive start time, inclusive end time, and required running seconds of task .
Output
Print one integer: the minimum total number of active time slots needed to satisfy every task.
Subtasks
-
Subtask 1 (20 points): ; ; for all .
-
Subtask 2 (30 points): ; ; for all .
-
Subtask 3 (50 points): ; ; for all .
Examples
Input
3
2 3 1
4 5 1
1 5 2
Output
2
Explanation
Task 1 needs one active slot in , task 2 needs one in , and task 3 needs two in . Turn the computer on at times and . The first two tasks receive one slot each, and the third receives both slots. The first two intervals are disjoint, so a single active time slot cannot suffice; the minimum is .