You manage n VM types. VM type i starts with inventory a[i] (number of available instances).
There are m customers arriving one by one. For each customer:
maxInv
be that largest inventory
before
the rental.
minPosInv
be the
smallest positive
inventory among all VM types
before
the rental (ignore VM types with inventory 0).
maxInv + minPosInv
.
Assume it is guaranteed that the total initial inventory is at least m.
Task: Compute the total revenue after processing all m customers.
n
,
m
a[1..n]
of non-negative integers
minPosInv
is always defined because total remaining inventory is positive while customers remain.
If a = [2, 1], m = 2:
maxInv=2
,
minPosInv=1
, revenue
3
, inventories ->
[1,1]
maxInv=1
,
minPosInv=1
, revenue
2
, inventories ->
[0,1]
Total revenue =
5
.