Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
0
Indexable
Never
def decreaseAndReturn2(clients, timeTillNow):
  print("input", clients, timeTillNow)
  response = []
  minTime = min(clients)
  extrTimeSpent = len(clients) * ((minTime)-1)
  timeTillNow = timeTillNow + extrTimeSpent
  completingTime = 0

  for clientIndx in range(len(clients)):
    if clients[clientIndx] - minTime > 0:
      response.append(clients[clientIndx] - minTime)
    elif clients[clientIndx] - minTime == 0:
      completingTime += timeTillNow + clientIndx + 1

  print("Response", response, completingTime, timeTillNow + len(clients))

  return response, completingTime, timeTillNow + len(clients)

def totalTimeForClients(clients):
  clientTimes = 0
  timeTillNow = 0
  currentClients = clients

  while currentClients:
      currentClients, totalTime, timeTillNow = process_items(currentClients, timeTillNow)
      clientTimes += totalTime

  return clientTimes % 1000000000

def process_items(clients, timeTillNow):

  new_clients = []
  completingTime = 0 

  for client_index, time_needed in enumerate(clients):
      if time_needed > 1:
          new_clients.append(time_needed - 1)
      else:
          completingTime += timeTillNow + 1 
  
      timeTillNow += 1
  
  return new_clients, completingTime, timeTillNow

print(totalTimeForClients([10000]))
Leave a Comment