#C3332. Minimum Sum of Subarray

    ID: 46748 Type: Default 1000ms 256MiB

Minimum Sum of Subarray

Minimum Sum of Subarray

You are given an array of integers and an integer k. Your task is to determine the minimum sum of any contiguous subarray of size k in the array. In mathematical notation, if the array is \(a_0, a_1, \ldots, a_{n-1}\), you need to compute

\(\min_{0 \le i \le n-k} \sum_{j=i}^{i+k-1} a_j\)

For example, given the array [1, 2, 3, 4, 5] and k = 2, the contiguous subarrays of size 2 are [1,2], [2,3], [3,4], and [4,5]. Their sums are 3, 5, 7, and 9 respectively. Hence, the answer is 3.

You need to process multiple test cases. The input will begin with an integer T denoting the number of test cases. Each test case consists of an integer n denoting the size of the array, followed by n space-separated integers representing the array elements, and then an integer k on the next line.

inputFormat

The first line of input contains a single integer T indicating the number of test cases. For each test case, the input is given as follows:

  • An integer n indicating the size of the array.
  • A line containing n space-separated integers (\(a_0, a_1, \dots, a_{n-1}\)).
  • An integer k on a new line representing the size of the subarray.

outputFormat

For each test case, print the minimum sum of any contiguous subarray of size k. Each result should be printed on a new line.

## sample
4
5
1 2 3 4 5
2
7
-1 -2 -3 -4 -5 -6 -7
3
4
5 6 7 8
2
3
-10 -20 -30
2
3

-18 11 -50

</p>