Question: Task Manager One day, John was curious about his laptop and wondered how the computer handles many different tasks at the same time. After reading
Task Manager One day, John was curious about his laptop and wondered how the computer handles many different tasks at the same time. After reading some books, he figured out that the CPU follows first-come-first-serve policy and uses queue to handle different tasks. In this model, each task has an arriving time R, a required processing time W, and priority level P (high priority or low priority). CPU will maintain two queues, one queue contains tasks of high priority and the other contains tasks of low priority. When a new task arrives, the CPU will put it into the queue according to the priority. And when the CPU finishes the current task, it will execute the next task extracted from the high priority queue and from the low priority queue if the high priority queue is empty. Can you write a program to compute the finishing time of each task? Input The input contains multiple test cases. For each test case, the first line contains an integer n, indicating that there are n tasks. The following n (1n 100) lines give the task information, where the i-th line contains three integers Ri, Wi, Pi, indicating the information of the i-th task, where 0 Ri 1000, 1Wi 100, 0 Pi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
