其他OA #12
Get Minimum Moves
估计中等评测数据准备中,可先阅读题面
Initially, all applications are deployed on n servers, with varying load handling capacities. The developers want to divide the n servers into clusters of cluster_size each such that the servers in each cluster have the same load-handling capacity. To achieve this, developers can recalibrate one or more servers. In one move, any server can be reconfigured to handle a lesser load than its current capacity, i.e., in one move capacity[i], can be changed to any integer value less than capacity[i].
Given the initial capacities of the servers, in an array, capacity, of size n, and an integer cluster_size, find the minimum number of moves required to divide the servers into clusters.
Function Description
Complete the function getMinimumMoves in the editor below.
getMinimumMoves has the following parameters:
int capacity[n]: the initial load-handling capacity of the serversint cluster_size: the size of each cluster Returns int: minimum moves to divide thenservers into clusters as mentioned above A supa huge thank-you to a wonderful friend for all the help!
Constraints
1 ≤ n ≤ 2 x 10⁵1 ≤ capacity[i] ≤ 10⁹1 ≤ cluster_size ≤ nnis a multiple ofcluster_size.
Example 1
Input:
capacity = [4, 2, 4, 4, 7, 4]
cluster_size = 3
Output:
2
Explanation: At least 2 moves to get clusters of size 3 each..
Example 2
Input:
capacity = [1,2,2,3,4,5,5,6]
cluster_size = 4
Output:
5
Explanation: 5 changes to get [1,1,1,1,2,2,2,2].
Example 3
Input:
capacity = [1,1,3,2]
cluster_size = 2
Output:
1
Explanation: 1 change to get [1,1,2,2].
Example 4
Input:
capacity = [5, 4, 2, 7, 1, 1, 5, 3, 4, 7, 4, 3, 6, 2, 1, 7, 5, 7, 5, 6, 5, 2, 1, 1, 1, 3, 4, 1, 7, 3]
cluster_size = 5
Output:
5
Explanation: 5 changes to get [1,1,1,1,1,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,7,7,7,7,7].