#C5308. Smallest Positive Contiguous Subarray Sum
Smallest Positive Contiguous Subarray Sum
Smallest Positive Contiguous Subarray Sum
Given an array \(B\) consisting of \(M\) integers, your task is to find the smallest positive integer \(X\) such that there exists at least one contiguous subarray within \(B\) whose sum equals \(X\). If no such contiguous subarray exists, print "Not Possible".
Note: A contiguous subarray is a sequence of consecutive elements of the array. The sum of a subarray \(B_i, B_{i+1}, \dots, B_j\) is defined as \(\sum_{k=i}^{j} B_k\).
Input/Output Format: This is an interactive problem where you will read input from stdin
and print your result to stdout
.
Example:
Input: 3 3 1 2 3 4 1 -2 3 4 5 -1 -1 -1 -1 -1</p>Output: 1 1 Not Possible
inputFormat
The first line contains an integer \(T\) representing the number of test cases. Each test case consists of two lines:
- The first line of each test case contains an integer \(N\) representing the number of elements in the array.
- The second line contains \(N\) space-separated integers which represent the elements of the array \(B\).
All input is provided via stdin
.
outputFormat
For each test case, output a single line. If there exists a contiguous subarray with a positive sum, print the smallest positive sum. Otherwise, print Not Possible
.
All outputs should be printed to stdout
.
3
3
1 2 3
4
1 -2 3 4
5
-1 -1 -1 -1 -1
1
1
Not Possible
</p>