Advertisement
qekaqeka

5419 КЕГЭ

Apr 16th, 2023
803
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. f = open(r'test.txt')
  2.  
  3. procs = list()
  4.  
  5. for s in f:
  6.     s = s.strip()
  7.     sl = s.split('\t')
  8.     id_ = int(sl[0])
  9.     dur = int(sl[1])
  10.     deps = list(map(int, sl[2].split(';')))
  11.  
  12.     procs.append([id_, dur, deps])
  13.  
  14. aim = len(procs) + 1
  15.  
  16. queue = list()
  17. finished = list()
  18. finished.append([0, 0, 0])
  19.  
  20. cors = [[0, 0, 0]] * 3
  21.  
  22. time = 0
  23.  
  24. while len(finished) != aim:
  25.     time += 1
  26.  
  27.     tqueue = list()
  28.    
  29.     for proc in procs:
  30.         f = True
  31.         for depid in proc[2]:
  32.             f2 = False
  33.             for finproc in finished:
  34.                 if finproc[0] == depid:
  35.                     f2 = True
  36.             f = f and f2
  37.         if f:
  38.             tqueue.append(proc.copy())
  39.  
  40.     for el in tqueue:
  41.         queue.append(el)
  42.         procs.remove(el)
  43.    
  44.     for i in range(3):
  45.         if cors[i][1] == 0 and len(queue) > 0:
  46.             cors[i] = queue[0]
  47.             del queue[0]
  48.  
  49.     for i in range(3):
  50.         if cors[i][1] > 0:
  51.             cors[i][1] -= 1
  52.  
  53.             if cors[i][1] == 0:
  54.                 finished.append(cors[i])
  55.                
  56. print(time + finished[-1][0])
  57.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement