# Help me to solve this DP question

The following task can be performed on an array of integers:

1.Choose a subarray of arr of size 1 at most x times.

2.Choose a subarray of arr of size 2 at most y times.

3.Choose a subaray of arr of size 3 at most z times.

The chosen subarrays should benon-overlapping. The profit is calculated as the sum of the elements in the chosen subarrays. What is the maxximum profit that can be obtained?

For example,

consider the array [1,2,3,4,5] for x,y and z each equal 1.

for x = 1, choose any one element from the array. Them maximum element is 5, so choose that one. It is the maximum profit under this scenario.

for y = 1, choose any subarray of two elements:[1,2],[2,3],[3,4] or [4,5]. The last subarray has the highest sum (profit) of 9.

for z = 1, the maximum profit is obtained with the subarray [3,4,5] with a sum of 12.

if you can choose one of each, maximum profit would be obtained by ignoring x then using y and z to capture [1,2] and [3,4,5] or [1,2,3] and [4,5] for a total profit of 15.

``````
Function Description:

def calculateProfit(arr,x,y,z):

constraints:

1<=n<=200

-10^5 <=arr[i] <= 10^5

0 <=x,y,z <= 20

Sample Input 1

n = 4

arr = [-7, 4, 0, -7]

x = 0

y = 1

z = 0

Sample Output 1

4

Sample Input 2

n = 4

arr = [-6, -3, -3, 10]

x = 0

y = 0

z = 1

Sample Output 2

4``````