Time limit
2s
Memory limit
128 MB
You are given a one-dimensional array of N integers, where 1 <= N <= 100. Choose exactly M intervals from the array, where 1 <= M <= ceil(N / 2), so that the total sum of all numbers contained in the chosen intervals is as large as possible.
The chosen intervals must satisfy all of the following conditions.
M intervals must be chosen; choosing fewer than M intervals is not allowed.Given the N integers, compute the maximum possible total sum.
The first line contains two integers N and M.
Each of the next N lines contains one integer from the array, in order. Every array value is an integer between -32768 and 32767, inclusive.
Print one integer: the maximum possible total sum of the numbers contained in the chosen intervals.