human
Maximum sum of a subsequence having difference between their indices equal to the difference between their values | Function to find the maximum sum of a subsequence having difference between indices equal to difference in their values.
Stores the maximum sum.
Stores the value for each A [ i ] - i.
Traverse the array.
Update the value in map.
Update the answer.
Finally , print the answer.
Driver Code.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to maximum sum of a subsequence having difference between their indices equal to the difference between their values and the other steps required.
 def maximumSubsequenceSum ( A , N ) :
	ans = 0
	mp = { }
	for i in range ( N ) :
		if ( A [ i ] - i in mp ) :
			mp [ A [ i ] - i ] += A [ i ]
		else :
			mp [ A [ i ] - i ] = A [ i ]
		ans = max ( ans , mp [ A [ i ] - i ] )
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	A = [ 10 , 7 , 1 , 9 , 10 , 1 ]
	N = len ( A )
	maximumSubsequenceSum ( A , N )