#C9643. Maximum Sum of K-Length Subarray

    ID: 53759 Type: Default 1000ms 256MiB

Maximum Sum of K-Length Subarray

Maximum Sum of K-Length Subarray

Given an array of integers \(A\) of length \(N\) and an integer \(K\), your task is to find the maximum sum of any contiguous subarray of length \(K\). In other words, compute

\(\max_{0 \le i \le N-K}\sum_{j=i}^{i+K-1} A[j]\)

You are required to write a program that reads multiple test cases from the standard input and outputs the results to the standard output. Each test case first provides the values \(N\) and \(K\) followed by \(N\) integers representing the array \(A\).

Note that \(K\) will always be less than or equal to \(N\). Ensure that your solution efficiently handles the input using a sliding window technique.

inputFormat

The first line contains an integer \(T\) representing the number of test cases. For each test case, the input is provided in two lines:

  1. The first line contains two space-separated integers \(N\) and \(K\), where \(N\) is the size of the array and \(K\) is the length of the subarray.
  2. The second line contains \(N\) space-separated integers representing the array \(A\).

Input is read from stdin.

outputFormat

For each test case, output a single line containing one integer --- the maximum sum of any contiguous subarray of length \(K\) from the array \(A\).

Output is written to stdout.

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

6 3

</p>