human
Cost of creating smallest subsequence with sum of difference between adjacent elements maximum | .
Initializing cost = 0.
To store the removed element.
This will store the sum of the subsequence.
Checking all the element of the vector.
Storing the value of arr [ i ] in temp variable.
If the situation like arr [ i - 1 ] < arr [ i ] < arr [ i + 1 ] or arr [ i - 1 ] > arr [ i ] > arr [ i + 1 ] occur remove arr [ i ] i . e , temp from sequence.
Insert the element in the set removedElements.
Storing the value of arr [ i ] in temp.
Taking the element not in removedElements.
Adding the value of elements of subsequence.
If we have to remove the element then we need to add the cost associated with the element.
Printing the sum of the subsequence with minimum length possible.
Printing the cost incurred in creating subsequence.
Driver code.
Calling the function"
How can the above be solved in Python?
 ... What is a code to cost of creating smallest subsequence with sum of difference between adjacent elements maximum and the other steps required?
assistant
#Here is code to cost of creating smallest subsequence with sum of difference between adjacent elements maximum and the other steps required.
 def costOfSubsequence ( N , arr , costArray ) :
	i , temp , cost = 0 , 0 , 0
	removedElements = { ' ' }
	ans = 0
	for i in range ( 1 , N - 1 ) :
		temp = arr [ i ]
		if ( ( ( arr [ i - 1 ] < temp ) and ( temp < arr [ i + 1 ] ) ) or ( ( arr [ i - 1 ] > temp ) and ( temp > arr [ i + 1 ] ) ) ) :
			removedElements . add ( temp )
	for i in range ( 0 , N ) :
		temp = arr [ i ]
		if ( temp not in removedElements ) :
			ans = ans + arr [ i ]
		else :
			cost += costArray [ i ]
	print ( ans , end = " , ▁ " )
	print ( cost )
N = 4
arr = [ 1 , 3 , 4 , 2 ]
costArray = [ 0 , 1 , 0 , 0 ]
costOfSubsequence ( N , arr , costArray )