#K3131. Max and Min Subarray Sums

    ID: 24891 Type: Default 1000ms 256MiB

Max and Min Subarray Sums

Max and Min Subarray Sums

You are given TT test cases. For each test case, you are provided with an integer nn followed by nn integers representing an array. Your task is to find the maximum contiguous subarray sum and the minimum contiguous subarray sum for each test case.

The maximum subarray sum is the largest possible sum of a contiguous subarray, and the minimum subarray sum is the smallest possible sum of a contiguous subarray. Use the well-known Kadane's algorithm to solve these problems efficiently.

Formally, given an array a1,a2,,ana_1, a_2, \dots, a_n, find: [ \text{maxSum} = \max_{1 \leq i \leq j \leq n} \sum_{k=i}^{j} a_k, \quad \text{minSum} = \min_{1 \leq i \leq j \leq n} \sum_{k=i}^{j} a_k. ]

inputFormat

The first line of input contains an integer TT, the number of test cases. Each test case starts with an integer nn on a new line, representing the number of elements in the array, followed by a line with nn space-separated integers.

outputFormat

For each test case, output a single line containing two space-separated integers: the maximum subarray sum and the minimum subarray sum.## sample

2
5
1 2 3 -2 5
4
-1 -2 -3 -4
9 -2

-1 -10

</p>