Maximizing Subarray sum with constrained traversal and addition time
Given two integers N and M representing the Length of arr and number of seconds. The task is to maximize the sum of the subarray where it takes 0.5secs to travel in consecutive elements and 0.5secs to add a value of the element in sum. It is given that one can start from any element.Example:Input: N = 7, M = 3, arr = { 2, 1, 3, 5, 0, 1, 4 }Output: 9Explanation: One can start from index 1 and move to index 2 and then to index 3. Hence, the total sum is = 1 + 3 + 5 = 9.Input: N = 6, M = 2, arr = { 1, 6, 2, 5, 3, 4…