#451 · Simulation · Expert · 230 XP · about 50 min
A bank has tellers tellers and one waiting line. customers lists everyone who comes in, as tuples (arrive, work, patience, vip), sorted by arrive, a whole number of minutes. Serving a customer takes work minutes: a customer whose service starts at minute s is done at minute s + work, and their teller is free again at that minute.
vip is True) joins the line behind the VIP customers already waiting, but in front of every regular customer. A regular customer joins at the back.patience minutes after arriving gives up and leaves the bank, unless a teller is free at that very minute.Write waits(tellers, customers) that returns a list with each customer's wait, the minute their service started minus the minute they arrived, in the same order as customers. Customers who gave up get -1.
waits(1, [(0, 5, 10, False), (1, 3, 10, False), (2, 2, 10, True)]) # returns [0, 6, 3] waits(1, [(0, 5, 10, False), (1, 3, 2, False)]) # returns [0, -1] waits(1, [(0, 3, 0, False), (1, 2, 2, False)]) # returns [0, 2]
In the first example the VIP who arrives at minute 2 goes ahead of the regular customer who arrived at minute 1, and is served at minute 5. In the second, the second customer gives up at minute 3, long before the teller is free. In the third, the teller becomes free at minute 3, the very minute the second customer's patience runs out, so they are served.
customers has 0 to 100,000 tuples.10**9, 1 <= work <= 10**6, 0 <= patience <= 10**9.First solves only, ranked by stars and then time.