Minimize cost to convert given two integers to zero using given operations | Function to find out the minimum cost to make two number X and Y equal to zero ; If x is greater than y then swap ; Cost of making y equal to x ; Cost if we choose 1 st operation ; Cost if we choose 2 nd operation ; Total cost ; Driver code
function makeZero ( x , y , a , b ) { if ( x > y ) { let temp = x ; x = y ; y = temp ; } let tot_cost = ( y - x ) * a ; let cost1 = 2 * x * a ; let cost2 = x * b ; tot_cost += Math . min ( cost1 , cost2 ) ; document . write ( tot_cost ) ; } let X = 1 , Y = 3 ; let cost1 = 391 , cost2 = 555 ; makeZero ( X , Y , cost1 , cost2 ) ;