#K52742. Maximizing Task Completion Under Deadlines
Maximizing Task Completion Under Deadlines
Maximizing Task Completion Under Deadlines
Problem Description:
Lena has a list of tasks, each defined by a required duration and a deadline. A task can be completed only if the cumulative sum of durations of tasks performed before it, plus its own duration, does not exceed its deadline. Formally, given a task represented as a pair ((d,t)), where (d) is the duration and (t) is the deadline, find the maximum number of tasks that can be performed in some order such that for each task in the order, (\text{current time} + d \le t) holds true. Tasks are 1-indexed based on their input order. Your output should include the maximum count of tasks and the sequence (order) in which the tasks are to be completed.
inputFormat
Input Format:
• The first line contains an integer (n) that denotes the number of tasks.
• Each of the following (n) lines contains two space-separated integers: the duration and the deadline of a task.
outputFormat
Output Format:
• The first line should display a single integer representing the maximum number of tasks that can be completed.
• The second line should list the indices of the tasks (1-indexed) in the order they should be performed, separated by a space. If no tasks can be completed, output an empty line.## sample
4
3 9
2 5
1 6
5 7
3
2 3 1
</p>