Problem · Greedy
Maximum Server Processing Time
Learn this problemProblem statement
An array processTime lists tasks in a fixed order. Split it into exactly numServers nonempty contiguous blocks, with every block containing at least m tasks.
A server's processing time is the sum of the m largest task times in its block. The servers execute sequentially, so the total processing time is the sum of their processing times. Return the maximum possible total.
Function
maxServerProcessingTime(processTime: int[], numServers: int, m: int) → longExamples
Example 1
processTime = [1,3,5,2,7,1,5,9]numServers = 3m = 2return = 31One optimal split has block scores 8, 9, and 14, totaling 31.
Example 2
processTime = [4,1,8,2]numServers = 2m = 1return = 12The two globally largest times, 8 and 4, can be captured in separate blocks.
Example 3
processTime = [5,2,7,3]numServers = 1m = 2return = 12With one block, the two largest task times sum to 12.
Constraints
1 <= numServers, mnumServers * m <= processTime.length <= 2 * 10^51 <= processTime[i] <= 10^9