Server Investment
Problem statement
A network security administrator manages several independent networks. For network i:
numServers[i]is the number of servers initially present.money[i]is the available upgrade budget.sell[i]is the amount earned by selling one server.upgrade[i]is the cost to upgrade one server.
You may sell any whole number of servers in a network. Sold servers cannot be upgraded, and the proceeds are added to that network's budget. You may then upgrade any number of the remaining servers that the resulting budget can afford.
Return an array where element i is the maximum number of servers that can be upgraded in network i.
Function
getMaxUpgradedServers(numServers: int[], money: int[], sell: int[], upgrade: int[]) → int[]Examples
Example 1
numServers = [4,3]money = [8,9]sell = [4,2]upgrade = [4,5]return = [3,2]For the first network, sell one server to obtain 8 + 4 = 12; the remaining three servers each cost 4 to upgrade. For the second network, sell one server to obtain 9 + 2 = 11; the remaining two servers cost 10 in total. Therefore the result is [3,2].
Example 2
numServers = [5,2]money = [50,0]sell = [1,3]upgrade = [10,4]return = [5,0]The first network can upgrade all five servers without selling any. In the second network, selling one server yields only 3, which cannot upgrade the one remaining server, so its maximum is 0.
Constraints
- For this exercise, assume the four arrays have the same length
n, where1 <= n <= 100000. - For this exercise, assume
0 <= numServers[i], money[i], sell[i] <= 10^9. - For this exercise, assume
1 <= upgrade[i] <= 10^9. - Use 64-bit integer arithmetic for funding calculations.