Pair with largest sum which is less than K in the array | Function to find pair with largest sum which is less than K in the array ; To store the break point ; Sort the given array ; Find the break point ; No need to look beyond i 'th index ; Find the required pair ; Print the required answer ; Driver code ; Function call
def Max_Sum ( arr , n , k ) : NEW_LINE INDENT p = n NEW_LINE arr . sort ( ) NEW_LINE for i in range ( 0 , n ) : NEW_LINE INDENT if ( arr [ i ] >= k ) : NEW_LINE INDENT p = i NEW_LINE break NEW_LINE DEDENT DEDENT maxsum = 0 NEW_LINE a = 0 NEW_LINE b = 0 NEW_LINE for i in range ( 0 , p ) : NEW_LINE INDENT for j in range ( i + 1 , p ) : NEW_LINE INDENT if ( arr [ i ] + arr [ j ] < k and arr [ i ] + arr [ j ] > maxsum ) : NEW_LINE INDENT maxsum = arr [ i ] + arr [ j ] NEW_LINE a = arr [ i ] NEW_LINE b = arr [ j ] NEW_LINE DEDENT DEDENT DEDENT print ( a , b ) NEW_LINE DEDENT arr = [ 5 , 20 , 110 , 100 , 10 ] NEW_LINE k = 85 NEW_LINE n = len ( arr ) NEW_LINE Max_Sum ( arr , n , k ) NEW_LINE