← 返回 amazon 的题目列表Cost Calculation for Adding Hubs
类型:online_judge
There are n warehouses, each with a capacity arranged in increasing order. Each warehouse is associated with a hub, where the associated hub's capacity must be greater than or equal to that of the warehouse. The last warehouse is the initial hub. Given a list of queries asking to add 2 hubs, calculate the total cost associated with the queries. Cost is defined as the difference in capacity from every warehouse to its nearest hub.
Example:
capacity = [0,2,5,9,12,18], additionalhubs = [[2,5],[1,3]]
Output: [12,18]
Example
Input
6
0
2
5
9
12
18
2
2
5
1
3