Maximize minimum array element possible by exactly K decrements | Function to find the maximized minimum element of the array after performing given operation exactly K times ; Stores the minimum element ; Traverse the given array ; Update the minimum element ; Stores the required operations to make all elements equal to the minimum element ; Update required operations ; If reqOperations < K ; Decrement the value of K by reqOperations ; Update minElement ; Return minimum element ; Driver Code
def minimumElement ( arr , N , K ) : NEW_LINE INDENT minElement = arr [ 0 ] ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT minElement = min ( minElement , arr [ i ] ) ; NEW_LINE DEDENT reqOperations = 0 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT reqOperations += arr [ i ] - minElement NEW_LINE DEDENT if ( reqOperations < K ) : NEW_LINE INDENT K -= reqOperations ; NEW_LINE minElement -= ( K + N - 1 ) // N ; NEW_LINE DEDENT return minElement ; NEW_LINE DEDENT arr = [ 10 , 10 , 10 , 10 ] ; NEW_LINE K = 7 ; NEW_LINE N = len ( arr ) NEW_LINE print ( minimumElement ( arr , N , K ) ) ; NEW_LINE