n Amazon's web infrastructure, the system logs n API requests per second. Each request's response time is stored in an array responseTimes, where each element represents the time taken to respond to a single request.
To prevent system overload, a throttling mechanism is applied with the following behavior:
In each step, select the request with the minimum response time.
If multiple requests have the same minimum response time, select the one with the lowest index.
Remove the selected request and its immediate neighbors (based on original indices) permanently from the log.
Repeat this process until all requests are removed.
Your task is to calculate the total cumulative response time of all selected minimum requests throughout the throttling process.
Example 1
Input:
responseTimes = [4, 2, 9, 1, 7, 3]
Process:
Select 1, remove neighbors 9 and 7
Select 2, remove neighbor 4
Select 3, remove itself
Selected values: 1 + 2 + 3 = 6
Output: 6
1 ≤ n ≤ 10^5
1 ≤ responseTimes[i] ≤ 10^9
If multiple minimum values exist, always choose the lowest index.
Neighbors are determined based on the original array indices.
The function should return a long (64-bit integer).
Hard