




'''simple docstring'''







from __future__ import annotations

from statistics import mean





def 		snake_case_							(_a			:							list[int]					,     _a			:							list[int]					,     _a			:							int  ):
    UpperCAmelCase     =	[0] * no_of_processes
    UpperCAmelCase     =	[0] * no_of_processes

    # Initialize remaining_time to waiting_time.

    for i in range(_a  ):
        UpperCAmelCase     =	burst_time[i]
    UpperCAmelCase     =	[]

    UpperCAmelCase     =	0
    UpperCAmelCase     =	0

    # When processes are not completed,
    # A process whose arrival time has passed \
    # and has remaining execution time is put into the ready_process.
    # The shortest process in the ready_process, target_process is executed.

    while completed != no_of_processes:
        UpperCAmelCase     =	[]
        UpperCAmelCase     =	-1

        for i in range(_a  ):
            if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
                ready_process.append(_a  )

        if len(_a  ) > 0:
            UpperCAmelCase     =	ready_process[0]
            for i in ready_process:
                if remaining_time[i] < remaining_time[target_process]:
                    UpperCAmelCase     =	i
            total_time += burst_time[target_process]
            completed += 1
            UpperCAmelCase     =	0
            UpperCAmelCase     =	(
                total_time - arrival_time[target_process] - burst_time[target_process]
            )
        else:
            total_time += 1

    return waiting_time





def 		snake_case_							(_a			:							list[int]					,     _a			:							int					,     _a			:							list[int]  ):
    UpperCAmelCase     =	[0] * no_of_processes
    for i in range(_a  ):
        UpperCAmelCase     =	burst_time[i] + waiting_time[i]
    return turn_around_time


if __name__ == "__main__":
   print('[TEST CASE 01]')

   A									=4
   A									=[2, 5, 3, 7]
   A									=[0, 0, 0, 0]
   A									=calculate_waitingtime(arrival_time, burst_time, no_of_processes)
   A									=calculate_turnaroundtime(
       burst_time, no_of_processes, waiting_time
   )

   # Printing the Result
   print('PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time')
   for i, process_id in enumerate(list(range(1, 5))):
      print(
          f"""{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t"""
          f"""{waiting_time[i]}\t\t\t\t{turn_around_time[i]}"""
      )
   print(f"""\nAverage waiting time = {mean(waiting_time):.5f}""")
   print(f"""Average turnaround time = {mean(turn_around_time):.5f}""")










'''simple docstring'''







from __future__ import annotations

import math


class     _a						:
       def __init__(			self		:			Dict     ,       lowercase		:			int       ):



           '''simple docstring'''

           UpperCAmelCase     =	size
           # approximate the overall size of segment tree with given value
           UpperCAmelCase     =	[0 for i in range(0     ,       4 * size       )]
           # create array to store lazy update
           UpperCAmelCase     =	[0 for i in range(0     ,       4 * size       )]
           UpperCAmelCase     =	[0 for i in range(0     ,       4 * size       )]  # flag for lazy update
       def 					A   (			self		:			List[str]     ,       lowercase		:			int       ):



           '''simple docstring'''

           return idx * 2
       def 					A   (			self		:			Optional[Any]     ,       lowercase		:			int       ):



           '''simple docstring'''

           return idx * 2 + 1
       def 					A   (			self		:			Dict     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			list[int]       ):



           '''simple docstring'''

           if left_element == right_element:
               UpperCAmelCase     =	a[left_element - 1]
           else:
               UpperCAmelCase     =	(left_element + right_element) // 2
               self.build(self.left(lowercase       )     ,       lowercase     ,       lowercase     ,       lowercase       )
               self.build(self.right(lowercase       )     ,       mid + 1     ,       lowercase     ,       lowercase       )
               UpperCAmelCase     =	max(
                   self.segment_tree[self.left(lowercase       )]     ,       self.segment_tree[self.right(lowercase       )]       )
       def 					A   (			self		:			Union[str, Any]     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int       ):



           '''simple docstring'''

           if self.flag[idx] is True:
               UpperCAmelCase     =	self.lazy[idx]
               UpperCAmelCase     =	False
               if left_element != right_element:
                   UpperCAmelCase     =	self.lazy[idx]
                   UpperCAmelCase     =	self.lazy[idx]
                   UpperCAmelCase     =	True
                   UpperCAmelCase     =	True

           if right_element < a or left_element > b:
               return True
           if left_element >= a and right_element <= b:
               UpperCAmelCase     =	val
               if left_element != right_element:
                   UpperCAmelCase     =	val
                   UpperCAmelCase     =	val
                   UpperCAmelCase     =	True
                   UpperCAmelCase     =	True
               return True
           UpperCAmelCase     =	(left_element + right_element) // 2
           self.update(self.left(lowercase       )     ,       lowercase     ,       lowercase     ,       lowercase     ,       lowercase     ,       lowercase       )
           self.update(self.right(lowercase       )     ,       mid + 1     ,       lowercase     ,       lowercase     ,       lowercase     ,       lowercase       )
           UpperCAmelCase     =	max(
               self.segment_tree[self.left(lowercase       )]     ,       self.segment_tree[self.right(lowercase       )]       )
           return True
       def 					A   (			self		:			Any     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int     ,       lowercase		:			int       ):



           '''simple docstring'''

           if self.flag[idx] is True:
               UpperCAmelCase     =	self.lazy[idx]
               UpperCAmelCase     =	False
               if left_element != right_element:
                   UpperCAmelCase     =	self.lazy[idx]
                   UpperCAmelCase     =	self.lazy[idx]
                   UpperCAmelCase     =	True
                   UpperCAmelCase     =	True
           if right_element < a or left_element > b:
               return -math.inf
           if left_element >= a and right_element <= b:
               return self.segment_tree[idx]
           UpperCAmelCase     =	(left_element + right_element) // 2
           UpperCAmelCase     =	self.query(self.left(lowercase       )     ,       lowercase     ,       lowercase     ,       lowercase     ,       lowercase       )
           UpperCAmelCase     =	self.query(self.right(lowercase       )     ,       mid + 1     ,       lowercase     ,       lowercase     ,       lowercase       )
           return max(lowercase     ,       lowercase       )







       def __str__(			self		:			Any       ):



           '''simple docstring'''

           return str([self.query(1     ,       1     ,       self.size     ,       lowercase     ,       lowercase       ) for i in range(1     ,       self.size + 1       )]       )


if __name__ == "__main__":
   A									=[1, 2, -4, 7, 3, -5, 6, 11, -20, 9, 14, 15, 5, 2, -8]
   A									=15
   A									=SegmentTree(size)
   segt.build(1, 1, size, A)
   print(segt.query(1, 1, size, 4, 6))
   print(segt.query(1, 1, size, 7, 11))
   print(segt.query(1, 1, size, 7, 12))
   segt.update(1, 1, size, 1, 3, 1_11)
   print(segt.query(1, 1, size, 1, 15))
   segt.update(1, 1, size, 7, 8, 2_35)
   print(segt)




