#C4571. Task Execution Simulation
Task Execution Simulation
Task Execution Simulation
You are given a set of machines and tasks. Each machine has a certain capacity which denotes how many tasks it can execute. Each task is associated with a priority and a required time (which is not used in the assignment process).
The simulation works as follows:
- Sort the tasks in descending order of priority. If two tasks have the same priority, the task with the smaller original index comes first. Mathematically, if task i has priority \(p_i\) and task j has priority \(p_j\), then task \(i\) comes before task \(j\) if \(p_i > p_j\), or if \(p_i = p_j\) and \(i < j\).
- Iterate over the sorted list, and for each task, assign it to the first machine (in machine order) that still has available capacity. The capacity of a machine is decremented by one when a task is assigned.
- If no machine has available capacity, the task is skipped.
The output is the order of task indices (1-indexed) in which they start execution.
inputFormat
The input is read from stdin and is structured as follows:
- The first line contains two integers \(n\) and \(m\), where \(n\) is the number of machines and \(m\) is the number of tasks.
- The second line contains \(n\) integers, representing the capacities of the machines.
- The following \(m\) lines each contain two integers, representing the priority and the required time of a task.
Note: Although the required time is given for each task, it does not affect the scheduling.
outputFormat
Print to stdout the indices of the tasks (1-indexed) in the order that they start execution. The indices should be separated by a single space. If no task is executed, print an empty line.
## sample3 5
2 1 3
5 7
3 2
1 5
4 3
3 4
1 4 2 5 3