#K69712. Maximum Sum Subarray

    ID: 33148 Type: Default 1000ms 256MiB

Maximum Sum Subarray

Maximum Sum Subarray

You are given an integer \(T\) representing the number of test cases. For each test case, you are provided with two integers \(N\) and \(K\) and an array of \(N\) integers. Your task is to find the contiguous subarray of length \(K\) that has the maximum sum.

Note: If there are multiple subarrays with the same maximum sum, return the one that appears first.

Hint: Consider using the sliding window technique to solve this problem efficiently.

inputFormat

The input is given from stdin and has the following format:

T
N K
a1 a2 a3 ... aN
... (repeated for T test cases)

Where:

  • T is the number of test cases.
  • For each test case, the first line contains two integers, \(N\) (the number of elements in the array) and \(K\) (the length of the subarray).
  • The second line contains \(N\) space-separated integers representing the array.
  • outputFormat

    For each test case, output the contiguous subarray of length \(K\) that has the maximum sum. Each subarray should be printed on a separate line. The numbers in each subarray should be space-separated. The output should be sent to stdout.

    ## sample
    1
    5 2
    1 2 3 -1 5
    
    2 3
    

    </p>