#K481. Maximum Profit from Consecutive Projects

    ID: 28345 Type: Default 1000ms 256MiB

Maximum Profit from Consecutive Projects

Maximum Profit from Consecutive Projects

You are given a sequence of projects, each with a profit value (which can be positive or negative). Your task is to choose exactly k consecutive projects such that the total profit is maximized.

More formally, given an array of integers \( P = [p_1, p_2, \dots, p_n] \) and an integer \( k \), you need to find the maximum sum of any contiguous subarray of length \( k \). This sum is defined as \[ max\_profit = \max_{1 \leq i \leq n-k+1} \left(\sum_{j=i}^{i+k-1} p_j\right). \]

The input will consist of multiple test cases. For each test case, the first line contains two integers \( n \) and \( k \) followed by a line of \( n \) integers representing the profit values of the projects. Your program should output the maximum possible profit for each test case on a separate line.

Example:

Input:
1
5 3
1 2 3 4 5

Output: 12

</p>

inputFormat

The first line of the input contains an integer \( T \) denoting the number of test cases. Each test case is described as follows:

  • The first line contains two integers \( n \) and \( k \), where \( n \) is the number of projects and \( k \) is the number of consecutive projects to select.
  • The second line contains \( n \) space-separated integers \( p_1, p_2, \dots, p_n \) representing the profit from each project.

It is guaranteed that \( 1 \leq k \leq n \leq 10^5 \) and that the absolute value of profit values does not exceed \( 10^9 \).

outputFormat

For each test case, output a single line containing the maximum profit that can be obtained by selecting exactly \( k \) consecutive projects.

## sample
1
5 3
1 2 3 4 5
12

</p>