Maximum Sum Subsequence | Function to print the maximum non - emepty subsequence sum ; Stores the maximum non - emepty subsequence sum in an array ; Stores the largest element in the array ; Traverse the array ; If a [ i ] is greater than 0 ; Update sum ; Driver Code
def MaxNonEmpSubSeq ( a , n ) : NEW_LINE INDENT sum = 0 NEW_LINE maxm = max ( a ) NEW_LINE if ( maxm <= 0 ) : NEW_LINE INDENT return maxm NEW_LINE DEDENT for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] > 0 ) : NEW_LINE INDENT sum += a [ i ] NEW_LINE DEDENT DEDENT return sum NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ - 2 , 11 , - 4 , 2 , - 3 , - 10 ] NEW_LINE N = len ( arr ) NEW_LINE print ( MaxNonEmpSubSeq ( arr , N ) ) NEW_LINE DEDENT