#C10095. Maximize Completed Tasks
Maximize Completed Tasks
Maximize Completed Tasks
You are given a set of n tasks. Each task has a priority and a completion time. You have a total available time t and your aim is to complete as many tasks as possible. Tasks must be attempted in order of descending priority. In case of a tie in priority, the task with the lower completion time should be chosen first.
The problem can be formulated as follows. Let each task be represented by a tuple \((p, c)\) where \(p\) is the priority and \(c\) is the completion time. After sorting the tasks by \(p\) in descending order and by \(c\) in ascending order, select tasks until the total time consumed exceeds \(t\). Determine the maximum number of tasks that can be completed.
The sorting criteria can be mathematically expressed as:
[ \text{Sort tasks such that } (p_i, c_i) \text{ comes before } (p_j, c_j) \text{ if } p_i > p_j \text{ or } (p_i = p_j \text{ and } c_i < c_j). ]
inputFormat
The first line of input contains two integers \(n\) and \(t\), where \(n\) is the number of tasks and \(t\) is the total available time.
Each of the following \(n\) lines contains two integers representing the priority and completion time of a task.
Input Example:
5 10 3 2 1 3 2 1 5 4 4 2
outputFormat
Output a single integer representing the maximum number of tasks that can be completed within the given time \(t\).
Output Example:
4## sample
5 10
3 2
1 3
2 1
5 4
4 2
4