Amazon's engineering team is working on enhancing their system's data processing efficiency. They have a set of n
servers, where the performance of the i
-th server is denoted by serverRates[i]
.
These servers are grouped into clusters of three, where the performance of a cluster, known as clusterPerformance
, is determined by the median value of the three servers' rates. Each server can only belong to one cluster, and some servers may remain ungrouped.
The goal is to compute the maximum possible total system performance, known as networkPerformance
, which is the sum of the performance values of all formed clusters.
Note: The median of a set of three values is the second value when sorted in either ascending or descending order.
Function Description
Implement the function computeMaxNetworkThroughput
in the editor.
The function has the following parameter:
int serverRates[n]
: an array representing the processing rates of the servers
Returns
long
: the maximum networkPerformance
that can be achieved
Example 1:
Input: serverRates = [4, 6, 3, 5, 4, 5]
Output: 9
Explanation:Here,
n = 6
, and the server processing rates areserverRates = [4, 6, 3, 5, 4, 5]
.The maximum number of clusters that can be formed is 2.
One possible way to create the clusters is:
- First cluster:
[4, 6, 3]
β Median = 4- Second cluster:
[5, 4, 5]
β Median = 5Thus, the total
networkPerformance
is4 + 5 = 9
.
Example 2:
Input: serverRates = [2, 3, 4, 3, 4]
Output: 4
Explanation:The maximum number of clusters that can be formed is 1, leaving two servers ungrouped.
One possible cluster configuration:
- First cluster:
[2, 4, 4]
β Median = 4Thus, the total
networkPerformance
for all clusters is4
.
1 β€ n β€ 2 * 10^5
1 β€ serverRates[i] β€ 10^9


input:
output: