human
Longest subsequence having maximum sum | Function to find the longest subsequence from the given array with maximum sum.
Stores the largest element of the array.
If Max is less than 0.
Print the largest element of the array.
Traverse the array.
If arr [ i ] is greater than or equal to 0.
Print elements of the subsequence.
Driver code"
Solution in Python:
assistant
#Here is code to longest subsequence having maximum sum and the other steps required.
 def longestSubWithMaxSum ( arr , N ) :
	Max = max ( arr )
	if ( Max < 0 ) :
		print ( Max )
		return
	for i in range ( N ) :
		if ( arr [ i ] >= 0 ) :
			print ( arr [ i ] , end = " ▁ " )
arr = [ 1 , 2 , - 4 , - 2 , 3 , 0 ]
N = len ( arr )
longestSubWithMaxSum ( arr , N )