#K40477. Maximum Sum Subarray of Fixed Length

    ID: 26651 Type: Default 1000ms 256MiB

Maximum Sum Subarray of Fixed Length

Maximum Sum Subarray of Fixed Length

Given T test cases, each test case consists of a sequence of N non-negative integers and an integer M. Your task is to find a contiguous subarray of length M such that its sum is maximized. In other words, for each test case, you need to compute:

\(\max_{0 \leq i \leq N-M} \sum_{j=i}^{i+M-1} A_j\)

This problem can be efficiently solved using a sliding window technique. Make sure that your solution reads input from stdin and outputs the result to stdout for each test case.

inputFormat

The first line of the input contains a single integer T, the number of test cases. For each test case, the first line contains two space-separated integers N and M, where N is the number of elements in the array and M is the subarray length to consider. The second line contains N space-separated non-negative integers representing the array A.

outputFormat

For each test case, output a single line containing one integer — the maximum sum of any contiguous subarray of length M.

## sample
2
5 3
1 2 3 4 5
7 2
10 5 2 7 8 7 4
12

15

</p>