Skip to content

Instantly share code, notes, and snippets.

@dons20
Last active April 1, 2019 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dons20/51901b19f43deeda5d5c79fe7497135a to your computer and use it in GitHub Desktop.
Save dons20/51901b19f43deeda5d5c79fe7497135a to your computer and use it in GitHub Desktop.
sampleInput1 = ("5 1\n"
"0 2 3\n"
"1 3 0\n"
"2 3 0\n"
"3 2 1\n"
"4 6 5\n"
)
def assign(orders):
entries = orders.rstrip().split('\n')
customers = []
for i in entries:
customers.append(i.rstrip().split())
n = int(customers[0][0])
s = int(customers[0][1])
customers.pop(0)
machines = {}
unfilled = []
# check if queue is needed
if len(customers) == s:
print("None")
return
for i in range(s): # fill machines with customers
machines[i] = customers[0]
customers.pop()
for c in customers: # handle remaining customers
for m in machines:
remainingTime = int(machines[m][0]) + int(machines[m][1])
if remainingTime <= int(c[0]):
machines[m] = c
break
elif int(c[2]) == 0 or remainingTime > int(c[2]):
unfilled.append(int(c[0]) + 1)
break
if unfilled == []:
print("None")
return
else:
print(*sorted(unfilled))
return unfilled
assign(sampleInput1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment