Simulate a serverless platform where each instance handles one request at a time.
Input: keepAlive coldMs execMs, then request arrival times (ms, non-decreasing).
For each request at time t:
- Examine existing instances in creation order. An instance that is free (busy until ≤ t) but whose last finish time is more than
keepAlivebefore t has expired: addkeepAliveto its idle time and retire it. - Among the remaining free instances, choose the one with the latest last finish time (most recently used; ties → lowest index). Add (t − last finish) to its idle time; the request runs warm: latency = execMs.
- If none, start a new instance: cold start, latency = coldMs + execMs.
Print t=900: warm on I3, latency 100 ms or t=0: COLD start I1, latency 600 ms. At the end, add keepAlive of final idle time to each instance not retired, and print Requests: n, cold starts: c (p%), average latency X ms (one decimal) and Instances: k, idle warm time billed: T ms.