#C2519. Maximum Subarray Sum with an Even Element

    ID: 45844 Type: Default 1000ms 256MiB

Maximum Subarray Sum with an Even Element

Maximum Subarray Sum with an Even Element

You are given an array of integers. Your task is to find the maximum subarray sum for any contiguous subarray that contains at least one even number.

A subarray is defined as a contiguous segment of the array. Formally, if the array is \(A_1, A_2, \dots, A_N\), you need to find: \[ \max_{1 \le i \le j \le N} \left\{ \sum_{k=i}^{j} A_k \;\middle|\; \exists\, k' \in [i,j] \text{ such that } A_{k'} \equiv 0 \pmod{2} \right\} \]

If no subarray contains an even number, output -inf.

inputFormat

The first line contains an integer \(T\), the number of test cases. Each test case is described as follows:

  • The first line of each test case contains an integer \(N\) denoting the size of the array.
  • The second line contains \(N\) space-separated integers representing the array \(A\).

outputFormat

For each test case, output a single line with the maximum subarray sum that includes at least one even number. If no valid subarray exists, output -inf.

## sample
2
5
1 2 3 -1 4
6
-1 -2 -3 -4 -5 -6
9

-2

</p>