Given an integer array and an integer , return the maximum sum of a non-empty subsequence such that for every two consecutive integers in the subsequence, and , where , the condition is satisfied.
You're solving a dynamic programming problem where the transition looks at the last states. A naive DP is . With a monotonic deque, it's .