Maximum number of teams of size K possible with each player from different country | Function to find if T number of teams can be formed or not ; Store the sum of array elements ; Traverse the array teams [ ] ; Required Condition ; Function to find the maximum number of teams possible ; Lower and Upper part of the range ; Perform the Binary Search ; Find the value of mid ; Perform the Binary Search ; Otherwise , update the search range ; Otherwise , update the search range ; Driver Code
def is_possible ( teams , T , k ) : NEW_LINE INDENT sum = 0 NEW_LINE for i in range ( len ( teams ) ) : NEW_LINE INDENT sum += min ( T , teams [ i ] ) NEW_LINE DEDENT return ( sum >= ( T * k ) ) NEW_LINE DEDENT def countOfTeams ( teams_list , N , K ) : NEW_LINE INDENT lb = 0 NEW_LINE ub = 1000000000 NEW_LINE while ( lb <= ub ) : NEW_LINE INDENT mid = lb + ( ub - lb ) // 2 NEW_LINE if ( is_possible ( teams_list , mid , K ) ) : NEW_LINE INDENT if ( is_possible ( teams_list , mid + 1 , K ) == False ) : NEW_LINE INDENT return mid NEW_LINE DEDENT else : NEW_LINE INDENT lb = mid + 1 NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT ub = mid - 1 NEW_LINE DEDENT DEDENT return 0 NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 4 ] NEW_LINE K = 2 NEW_LINE N = len ( arr ) NEW_LINE print ( countOfTeams ( arr , N , K ) ) NEW_LINE DEDENT