Maximize product of array by replacing array elements with its sum or product with element from another array | C # program for the above approach ; Function to find the largest product of array A [ ] ; Base Case ; Store all the elements of the array A [ ] ; Sort the Array B [ ] ; Traverse the array B [ ] ; Pop minimum element ; Check which operation is producing maximum element ; Insert resultant element into the priority queue ; Evaluate the product of the elements of A [ ] ; Return the maximum product ; Driver Code ; Given arrays ; Function Call
using System ; using System . Collections . Generic ; class GFG { public static int largeProduct ( int [ ] A , int [ ] B , int N ) { if ( N == 0 ) { return 0 ; } List < int > pq = new List < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { pq . Add ( A [ i ] ) ; } Array . Sort ( B ) ; pq . Sort ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int min = pq [ 0 ] ; pq . RemoveAt ( 0 ) ; int maximized_element = Math . Max ( min * B [ i ] , min + B [ i ] ) ; pq . Add ( maximized_element ) ; pq . Sort ( ) ; } int max_product = 1 ; while ( pq . Count > 0 ) { max_product *= pq [ 0 ] ; pq . RemoveAt ( 0 ) ; } return max_product ; } static public void Main ( ) { int [ ] A = { 1 , 1 , 10 } ; int [ ] B = { 1 , 1 , 1 } ; int N = 3 ; Console . WriteLine ( largeProduct ( A , B , N ) ) ; } }