For each hour t you choose a server count s_t with demand[t] ≤ s_t ≤ max_servers. The cost is
run_cost × s_t per hour plus change_cost × |s_t − s_{t−1}| for scaling, where s_{−1} = initial.
Return {"cost": minimum_total_cost, "plan": [s_0, s_1, ...]}. If several plans cost the same, return the
lexicographically smallest. If any demand exceeds max_servers, return None.
Implement plan_capacity. Input: demand: list[int], max_servers: int, initial: int, run_cost: int, change_cost: int. Returns: dict | None.
Dropping to 1 server saves 2 in running cost but costs 4 + 4 in scaling.
def plan_capacity(demand, max_servers, initial, run_cost, change_cost):
plan = list(demand)
prev, cost = initial, 0
for s in plan:
cost += run_cost * s + change_cost * abs(s - prev)
prev = s
return {"cost": cost, "plan": plan}
Run executes the public tests. Submit grades against public and hidden tests.
For each hour t you choose a server count s_t with demand[t] ≤ s_t ≤ max_servers. The cost is
run_cost × s_t per hour plus change_cost × |s_t − s_{t−1}| for scaling, where s_{−1} = initial.
Return {"cost": minimum_total_cost, "plan": [s_0, s_1, ...]}. If several plans cost the same, return the
lexicographically smallest. If any demand exceeds max_servers, return None.
Implement plan_capacity. Input: demand: list[int], max_servers: int, initial: int, run_cost: int, change_cost: int. Returns: dict | None.
Dropping to 1 server saves 2 in running cost but costs 4 + 4 in scaling.
def plan_capacity(demand, max_servers, initial, run_cost, change_cost):
plan = list(demand)
prev, cost = initial, 0
for s in plan:
cost += run_cost * s + change_cost * abs(s - prev)
prev = s
return {"cost": cost, "plan": plan}
Run executes the public tests. Submit grades against public and hidden tests.