#C14307. FCFS Process Scheduling Completion Times

    ID: 43942 Type: Default 1000ms 256MiB

FCFS Process Scheduling Completion Times

FCFS Process Scheduling Completion Times

In this problem, you are required to simulate the First-Come, First-Served (FCFS) scheduling algorithm. Given two sequences representing the arrival times and burst times of processes, you must compute the completion times for each process. The FCFS scheduling algorithm works as follows:

  • If the CPU is idle and a process arrives, the CPU immediately begins executing that process.
  • If the CPU is busy, arriving processes wait in a queue and are processed in the order of their arrival.

The completion time of a process is defined as the time at which the process finishes execution. Mathematically, if (a_i) represents the arrival time and (b_i) the burst time of the (i)-th process, the completion time (C_i) is given by:

[ C_i = \max\left(C_{i-1}, a_i\right) + b_i ]

Your solution must read input from standard input and write output to standard output.

inputFormat

The first line contains an integer (n) indicating the number of processes. The second line contains (n) space-separated integers representing the arrival times of the processes. The third line contains (n) space-separated integers representing the burst times of the processes.

outputFormat

Output (n) space-separated integers on a single line, where the (i)-th integer represents the completion time of the (i)-th process.## sample

4
0 2 4 6
3 6 4 5
3 9 13 18