`{"id":"e6732fcb-4aab-4bde-b7e5-e550134476f5","name":"Maximum Sum Of M Non-overlapping Subarrays","description":"1. You are given an array(arr) of positive numbers and two numbers M and K.\r\n2. You have to find the maximum sum of M non-overlapping subarrays of size K.\r\n3. The size of the given array(arr) is greater than M*K.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nTwo numbers M and K","outputFormat":"A number representing maximum sum of M non-overlapping subarrays of size K.","constraints":"1 &lt;= N &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3\r\nM &gt;= 1\r\nK &gt;= 1\r\nN &gt;= M*K","sampleCode":{"cpp":{"code":""},"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 m, int k){\r\n\t\t// write your code here\r\n\t\t\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 int m = scn.nextInt();\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, m , k));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"7\r\n2 10 7 18 5 33 0\r\n3\r\n1","sampleOutput":"61\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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"233c3844-e199-4b36-a418-8d89afbc3136","name":"Maximum Sum Of M Non-overlapping Subarrays","slug":"maximum-sum-of-m-non-overlapping-subarrays","type":1}],"next":{"id":"a348f8e2-5c16-4f92-bc85-04f182133f7e","name":"Maximum sum of M non-overlapping subarrays MCQ","type":0,"slug":"maximum-sum-of-m-non-overlapping-subarrays-mcq"},"prev":{"id":"6e65ed40-c376-41ca-a262-40b5a241da7e","name":"Maximum Sum Of Three Non-overlapping Subarrays ","type":1,"slug":"maximum-sum-of-three-non-overlapping-subarrays"}}}`

# Maximum Sum Of M Non-overlapping Subarrays

1. You are given an array(arr) of positive numbers and two numbers M and K. 2. You have to find the maximum sum of M non-overlapping subarrays of size K. 3. The size of the given array(arr) is greater than M*K.

`{"id":"e6732fcb-4aab-4bde-b7e5-e550134476f5","name":"Maximum Sum Of M Non-overlapping Subarrays","description":"1. You are given an array(arr) of positive numbers and two numbers M and K.\r\n2. You have to find the maximum sum of M non-overlapping subarrays of size K.\r\n3. The size of the given array(arr) is greater than M*K.","inputFormat":"A number N\r\narr1\r\narr2.. N numbers\r\nTwo numbers M and K","outputFormat":"A number representing maximum sum of M non-overlapping subarrays of size K.","constraints":"1 &lt;= N &lt;= 10^3\r\n1 &lt;= arr[i] &lt;= 10^3\r\nM &gt;= 1\r\nK &gt;= 1\r\nN &gt;= M*K","sampleCode":{"cpp":{"code":""},"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 m, int k){\r\n\t\t// write your code here\r\n\t\t\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 int m = scn.nextInt();\r\n int k = scn.nextInt();\r\n System.out.println(solution(arr, m , k));\r\n\t}\r\n\r\n}"},"node":{"code":""},"ruby":{"code":""},"python":{"code":""}},"points":10,"difficulty":"hard","sampleInput":"7\r\n2 10 7 18 5 33 0\r\n3\r\n1","sampleOutput":"61\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":"5539a6e8-c8bf-4f04-805c-e43e9d20e72a","name":"Dynamic Programming For Intermediate","slug":"dynamic-programming-for-intermediate-408","type":0},{"id":"233c3844-e199-4b36-a418-8d89afbc3136","name":"Maximum Sum Of M Non-overlapping Subarrays","slug":"maximum-sum-of-m-non-overlapping-subarrays","type":1}],"next":{"id":"a348f8e2-5c16-4f92-bc85-04f182133f7e","name":"Maximum sum of M non-overlapping subarrays MCQ","type":0,"slug":"maximum-sum-of-m-non-overlapping-subarrays-mcq"},"prev":{"id":"6e65ed40-c376-41ca-a262-40b5a241da7e","name":"Maximum Sum Of Three Non-overlapping Subarrays ","type":1,"slug":"maximum-sum-of-three-non-overlapping-subarrays"}}}`

Editor

# Maximum Sum Of M Non-overlapping Subarrays

hard

1. You are given an array(arr) of positive numbers and two numbers M and K. 2. You have to find the maximum sum of M non-overlapping subarrays of size K. 3. The size of the given array(arr) is greater than M*K.

## Constraints

1 <= N <= 10^3 1 <= arr[i] <= 10^3 M >= 1 K >= 1 N >= M*K

## Format

### Input

A number N arr1 arr2.. N numbers Two numbers M and K

### Output

A number representing maximum sum of M non-overlapping subarrays of size K.

## 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;}7 2 10 7 18 5 33 0 3 1```

### 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;}61 ```

Discussions

Show Discussion

Related Resources