You are given an array A consisting of N integers and a special number K. You have to divide the array into K non-empty subarrays. The sum of elements of the 1st, 3rd, 5th, 7th...(odd) subarrays is the price at which you buy the stocks and the sum of elements of the 2nd, 4th, 6th, 8th....(even) subarrays is the price at which you sell the stocks. The profit of this transaction would be equal to = selling price - buying price, where the selling price is the sum of elements of the even indexed subarrays and the buying price is the sum of elements of the odd indexed subarrays.
Task
Determine the maximum profit you can make by buying and selling the stocks in an optimal manner.
Example
Assumptions
Approach
Function description
Complete the function solve provided in the editor. This function takes the following 3 parameters and returns the required answer:
Input format
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button)
Output format
For each test case in a new line, print a single integer representing the maximum profit.
Constraints
1≤T≤10
1≤N≤104
−109≤Ai≤109
1≤K≤min(N,102)
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
The first line contains the number of test cases, T = 1.
The first test case
Given
Approach