Problem · Array
Repeated Maximum and Minimum Request Score
Learn this problemProblem statement
Process requests operations on the integer array values. During each operation:
- Read the current minimum and current maximum value.
- Add their sum to a running score.
- Choose any one occurrence of the current maximum and decrease it by
1.
Return the score after all requests. When several entries equal the maximum, choosing any of them produces the same multiset for the next operation.
Function
maximumMinimumRequestScore(values: int[], requests: int) → longExamples
Example 1
values = [3,1,4]requests = 2return = 9The request sums are 4 + 1 = 5 and then 3 + 1 = 4, totaling 9.
Example 2
values = [5]requests = 3return = 24The same element is both minimum and maximum, producing 10, 8, and 6.
Example 3
values = [1,1,1]requests = 4return = 4After each tied maximum is decremented, zero becomes the minimum for later requests.
Constraints
1 <= values.length, requests <= 100000.-10^9 <= values[i] <= 10^9.- The final score fits in a signed 64-bit integer.