#K73197. Maximum Non-Overlapping Tasks Scheduling
Maximum Non-Overlapping Tasks Scheduling
Maximum Non-Overlapping Tasks Scheduling
This problem requires you to select the maximum number of non-overlapping tasks from a given set, under the constraint that the total resource usage of the selected tasks does not exceed a specified limit.
Each task is represented by three integers: the starting time, the ending time, and the required resources. Two tasks are considered non-overlapping if the starting time of the current task is greater than or equal to the ending time of the last selected task. Additionally, the sum of the resource requirements of the chosen tasks should not exceed the available resources.
You are to implement a greedy strategy: first, sort the tasks by their ending times. Then, iteratively select the tasks that do not overlap and whose cumulative resource consumption remains within the limit.
The resource constraint is formulated as follows: Let \( R \) be the total available resources and \( r_i \) be the resource requirement for task \( i \). For the selected tasks \( T \), it must hold that \[ \sum_{i \in T} r_i \leq R. \]
inputFormat
The input is read from stdin and has the following format:
n r start_1 end_1 res_1 start_2 end_2 res_2 ... start_n end_n res_n
Where:
n
is an integer representing the number of tasks.r
is an integer representing the total available resources.- Each of the following
n
lines contains three space-separated integers indicating the starting time, ending time, and resource requirement of a task.
</p>
outputFormat
The output, written to stdout, is a single integer representing the maximum number of tasks that can be scheduled such that they do not overlap and their total resource consumption does not exceed the given limit.
## sample5 10
1 4 2
2 6 4
5 8 3
7 9 3
8 10 5
3