#C367. Maximum Subarray Sum with At Least One Negative Element

    ID: 47122 Type: Default 1000ms 256MiB

Maximum Subarray Sum with At Least One Negative Element

Maximum Subarray Sum with At Least One Negative Element

You are given an array of N integers representing the magical energies of stones. Your task is to find the maximum sum of any contiguous subarray that contains at least one negative element. If no negative element exists in the entire array, output \(-\infty\) (represented as "-inf" in the output).

Details:

  • A contiguous subarray is a sequence of elements that appear consecutively in the array.
  • The answer is defined as the maximum sum over all contiguous subarrays that include at least one negative number.
  • If the array does not contain any negative number, then the answer is defined as \(-\infty\), which should be printed as "-inf".

Note on \(-\infty\): In the context of this problem, when no negative number exists in any subarray, the maximum sum is considered to be \(-\infty\), indicating that the condition is not satisfied.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains an integer N denoting the number of stones.
  2. The second line contains N space-separated integers representing the energies of the stones.

outputFormat

Output the maximum sum of any contiguous subarray that contains at least one negative element. If no subarray satisfies the condition (i.e. there is no negative element in the array), output "-inf".

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

</p>