Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- from datetime import datetime, timedelta
- data = input().split(";")
- time = datetime.strptime(input(), '%H:%M:%S')
- robots = []
- available_robots = deque([])
- products = []
- for el in data:
- robot_data = el.split('-')
- robot = {}
- robot['name'] = robot_data[0]
- robot['processing_time'] = int(robot_data[1])
- robot['avaible_at'] = time
- robots.append(robot)
- available_robots.append(robot)
- product = input()
- while not product == "End":
- products.append(product)
- product = input()
- products = deque(products)
- time = time + timedelta(seconds=1)
- while len(products) > 0:
- current_product = products.popleft()
- if available_robots:
- current_robot = available_robots.popleft()
- current_robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
- robot = [el for el in robots if el == current_robot][0]
- robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
- print (f"{robot['name']} - {current_product} [{time.strftime('%H:%M:%S')}]")
- else:
- for r in robots:
- if time >= r['avaible_at']:
- available_robots.append(r)
- if not available_robots:
- products.append(current_product)
- else:
- current_robot = available_robots.popleft()
- current_robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
- robot = [el for el in robots if el == current_robot][0]
- robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
- print(f"{robot['name']} - {current_product} [{time.strftime('%H:%M:%S')}]")
- time = time + timedelta(seconds=1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement