Maximum number of customers that can be satisfied with given quantity | Python3 program to find maximum number of customers that can be satisfied ; print maximum number of satisfied customers and their indexes ; Creating an vector of pair of total demand and customer number ; Sorting the customers according to their total demand ; Taking the first k customers that can be satisfied by total amount d ; Driver Code ; Initializing variables
v = [ ] NEW_LINE def solve ( n , d , a , b , arr ) : NEW_LINE INDENT first , second = 0 , 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT m = arr [ i ] [ 0 ] NEW_LINE t = arr [ i ] [ 1 ] NEW_LINE v . append ( [ a * m + b * t , i + 1 ] ) NEW_LINE DEDENT v . sort ( ) NEW_LINE ans = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if v [ i ] [ first ] <= d : NEW_LINE INDENT ans . append ( v [ i ] [ second ] ) NEW_LINE d -= v [ i ] [ first ] NEW_LINE DEDENT DEDENT print ( len ( ans ) ) NEW_LINE for i in range ( len ( ans ) ) : NEW_LINE INDENT print ( ans [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT n = 5 NEW_LINE d = 5 NEW_LINE a = 1 NEW_LINE b = 1 NEW_LINE arr = [ [ 2 , 0 ] , [ 3 , 2 ] , [ 4 , 4 ] , [ 10 , 0 ] , [ 0 , 1 ] ] NEW_LINE solve ( n , d , a , b , arr ) NEW_LINE DEDENT