Use Minimum Tokens
Amazon operates a system of n warehouses, each represented by warehouse[i], where warehouse[i] indicates the maximum number of items that particular warehouse can hold. Additionally, there are q shipments to process, represented by a 2D array catalog[i][2]. Each shipment has specific requirements:
catalog[i][0] denotes the minimum capacity that the selected warehouse must have to accommodate the shipment.catalog[i][1] denotes the minimum combined capacity required from the other warehouses to fulfill backup storage needs.Amazon can increase the capacity of any warehouse by spending 1 token per unit of capacity.
The task is to determine the optimal strategy for allocating capacity for each shipment such that the fewest number of tokens are expended. This strategy must ensure that the selected warehouse meets the required capacity for the shipment and that the combined capacity of the other warehouses is sufficient for backup storage.
Note
i is selected to accommodate the shipment and if there are some left over capacity (i.e., warehouse[i] - catalog[i][0] > 0) then it cannot be used for backup storage.
Complete the function useMinimumTokens in the editor.
useMinimumTokens has the following parameters:
int warehouse[n]: an array listing the initial maximum capacity of each warehouse.long catalog[q][2]: A 2D array describing the shipments.
Returns
long[q]: An array representing the minimum number of tokens needed to serve each shipment while ensuring sufficient backup storage.
1Example 1
2Example 2
Constraints
Limits and guarantees your solution can rely on.
2 ≤ n ≤ 10^51 ≤ warehouse[i] ≤ 10^91 ≤ q ≤ 10^51 ≤ catalog[i][0] ≤ 10^91 ≤ catalog[i][1] ≤ 10^15