Maximize profit that can be earned by selling an item among N buyers | Python3 program for the above approach ; Function to find the maximum profit earned by selling an item among N buyers ; Stores the maximum profit ; Stores the price of the item ; Sort the array ; Traverse the array ; Count of buyers with budget >= arr [ i ] ; Update the maximum profit ; Return the maximum possible price ; Driver code
import sys NEW_LINE def maximumProfit ( arr , N ) : NEW_LINE INDENT ans = - sys . maxsize - 1 NEW_LINE price = 0 NEW_LINE arr . sort ( ) NEW_LINE for i in range ( N ) : NEW_LINE INDENT count = ( N - i ) NEW_LINE if ( ans < count * arr [ i ] ) : NEW_LINE INDENT price = arr [ i ] NEW_LINE ans = count * arr [ i ] NEW_LINE DEDENT DEDENT return price NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 22 , 87 , 9 , 50 , 56 , 43 ] NEW_LINE print ( maximumProfit ( arr , 6 ) ) NEW_LINE DEDENT