#K53212. Contiguous Subarray Sum Problem

    ID: 29482 Type: Default 1000ms 256MiB

Contiguous Subarray Sum Problem

Contiguous Subarray Sum Problem

You are given an array of integers representing the magical powers of a series of books. Your task is to determine whether there exists a contiguous subarray (i.e. a sequence of consecutive elements) whose sum equals a given target value \(S\). Formally, you need to check if there exist indices \(l\) and \(r\) (with \(1 \le l \le r \le N\)) such that

\(\sum_{i=l}^{r} a_i = S\)

If such a subarray exists, output POSSIBLE, otherwise output IMPOSSIBLE.

Note: The subarray must be contiguous. The input always begins with an integer \(N\) (the number of books) and an integer \(S\) (the target sum), followed by \(N\) space-separated integers representing the array.

inputFormat

The first line of input contains two integers \(N\) and \(S\), where \(N\) is the number of books and \(S\) is the target sum.

The second line contains \(N\) space-separated integers representing the magical powers of the books.

Example:

6 15
2 -1 3 4 1 6

outputFormat

Output a single line: POSSIBLE if there exists a contiguous subarray whose sum equals \(S\), or IMPOSSIBLE otherwise.

Example:

POSSIBLE
## sample
6 15
2 -1 3 4 1 6
POSSIBLE

</p>