`{"id":"3a3c4933-18c5-43a1-8e14-0083c4a32dfc","name":"Maximum Sum Of Two Non-overlapping Subarrays","description":"1. You are given an array(arr) of positive numbers and two numbers X and Y.\r\n2. You have to find the maximum sum of elements in two non-overlapping subarrays.\r\n3. One subarray must of length X and the other must be of length Y.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nTwo numbers X and Y","outputFormat":"A number representing maximum sum of elements in two non-overlapping subarrays. ","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 1000\r\nX &gt;= 1, Y &gt;= 1\r\nX + Y &lt;= N","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nint solution(vector<int> arr, int x, int y){\n\treturn 0;\n}\nint main() {\n\tint n = 0;\n\tcin>>n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tcin>>arr[i];\n\t}\n\tint x = 0;\n\tcin>>x;\n\tint y = 0;\n\tcin>>y;\n\tcout<<solution(arr,x,y)<<endl;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[] arr, int x, int y){\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < arr.length; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tint x = scn.nextInt();\r\n\t\tint y = scn.nextInt();\r\n\t\tSystem.out.println(solution(arr,x,y));\r\n\t}\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"9\r\n0 6 5 2 2 5 1 9 4\r\n1\r\n2","sampleOutput":"20\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"bf943f24-4ace-4d3b-8043-2bfed550f55b","name":"LeetCode Solutions","slug":"leetcode-solutions","type":0},{"id":"b24be105-0644-4882-8cd6-28543b24838b","name":"Maximum Sum Of Two Non-overlapping Subarrays","slug":"maximum-sum-of-two-non-overlapping-subarrays","type":1}],"next":{"id":"ec065fcb-9abb-44e3-97cc-343e04e09058","name":"Remove Element","type":1,"slug":"remove-element"},"prev":{"id":"a2e9342f-283f-45cc-bf4b-57942536831f","name":"Special Positions in a Binary Matrix","type":1,"slug":"special-positions-in-a-binary-matrix"}}}`

# Maximum Sum Of Two Non-overlapping Subarrays

1. You are given an array(arr) of positive numbers and two numbers X and Y. 2. You have to find the maximum sum of elements in two non-overlapping subarrays. 3. One subarray must of length X and the other must be of length Y.

`{"id":"3a3c4933-18c5-43a1-8e14-0083c4a32dfc","name":"Maximum Sum Of Two Non-overlapping Subarrays","description":"1. You are given an array(arr) of positive numbers and two numbers X and Y.\r\n2. You have to find the maximum sum of elements in two non-overlapping subarrays.\r\n3. One subarray must of length X and the other must be of length Y.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nTwo numbers X and Y","outputFormat":"A number representing maximum sum of elements in two non-overlapping subarrays. ","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 1000\r\nX &gt;= 1, Y &gt;= 1\r\nX + Y &lt;= N","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nint solution(vector<int> arr, int x, int y){\n\treturn 0;\n}\nint main() {\n\tint n = 0;\n\tcin>>n;\n\tvector<int> arr(n);\n\tfor(int i = 0 ; i < n; i++){\n\t\tcin>>arr[i];\n\t}\n\tint x = 0;\n\tcin>>x;\n\tint y = 0;\n\tcin>>y;\n\tcout<<solution(arr,x,y)<<endl;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static int solution(int[] arr, int x, int y){\r\n\t\t// write your code here\r\n\r\n\t\treturn 0;\r\n\t}\r\n\t\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n\t\tint[] arr = new int[n];\r\n\t\tfor(int i = 0 ; i < arr.length; i++){\r\n\t\t\tarr[i] = scn.nextInt();\r\n\t\t}\r\n\t\tint x = scn.nextInt();\r\n\t\tint y = scn.nextInt();\r\n\t\tSystem.out.println(solution(arr,x,y));\r\n\t}\r\n\r\n}"},"python":{"code":""}},"points":10,"difficulty":"medium","sampleInput":"9\r\n0 6 5 2 2 5 1 9 4\r\n1\r\n2","sampleOutput":"20\r\n","questionVideo":"","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"bf943f24-4ace-4d3b-8043-2bfed550f55b","name":"LeetCode Solutions","slug":"leetcode-solutions","type":0},{"id":"b24be105-0644-4882-8cd6-28543b24838b","name":"Maximum Sum Of Two Non-overlapping Subarrays","slug":"maximum-sum-of-two-non-overlapping-subarrays","type":1}],"next":{"id":"ec065fcb-9abb-44e3-97cc-343e04e09058","name":"Remove Element","type":1,"slug":"remove-element"},"prev":{"id":"a2e9342f-283f-45cc-bf4b-57942536831f","name":"Special Positions in a Binary Matrix","type":1,"slug":"special-positions-in-a-binary-matrix"}}}`

Editor

# Maximum Sum Of Two Non-overlapping Subarrays

medium

1. You are given an array(arr) of positive numbers and two numbers X and Y. 2. You have to find the maximum sum of elements in two non-overlapping subarrays. 3. One subarray must of length X and the other must be of length Y.

## Constraints

1 <= N <= 1000 0 <= arr[i] <= 1000 X >= 1, Y >= 1 X + Y <= N

## Format

### Input

A number N arr1 arr2.. N numbers Two numbers X and Y

### Output

A number representing maximum sum of elements in two non-overlapping subarrays.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}9 0 6 5 2 2 5 1 9 4 1 2```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}20 ```

Discussions

Show Discussion

Related Resources