You are given a list of tasks. Each task is represented by two integers:
[id, deadline]
where:
id is the type/ID of the task.deadline is the latest time by which the task must be completed.Each task takes 1 unit of time to complete.
You are also given an integer cooldown.
Your goal is to complete the maximum possible number of tasks while satisfying all deadlines and the following cooldown rule.
Consider two consecutively completed tasks:
cooldown units must be applied before another task with the same ID can be completed.You may choose the order in which tasks are executed, and you are not required to complete every task.
A task can only be completed if its completion time does not exceed its deadline.
Return the maximum number of tasks that can be completed.
N, the number of tasks.N lines contain two integers id and , representing each task.deadlinecooldown.Print a single integer representing the maximum number of tasks that can be completed.
5
1 2
1 5
2 2
2 4
1 7
1
4
A valid ordering can be constructed by alternating task IDs whenever possible.
For example:
Task ID: 1 → 2 → 1 → 2
Since consecutive tasks have different IDs, no cooldown is required between them.
The selected tasks can all be completed within their respective deadlines, giving a maximum of 4 completed tasks.
1 ≤ N ≤ 2 × 10^51 ≤ id ≤ 10^91 ≤ deadline ≤ 10^90 ≤ cooldown ≤ 10^9Teradata • Pending