#C14953. Sublist Sum Existence

    ID: 44659 Type: Default 1000ms 256MiB

Sublist Sum Existence

Sublist Sum Existence

Given an array of integers and a target sum \(T\), determine whether there exists a contiguous subarray that sums exactly to \(T\). If such a subarray exists, output True; otherwise, output False.

Example:

  • For the input array [1, 2, 3, 7, 5] and target sum \(12\), one possible contiguous subarray is [2, 3, 7] which sums to 12, so the answer is True.
  • For the input array [1, 2, 3, 4, 5] and target sum \(20\), no such contiguous subarray exists, so the answer is False.

inputFormat

The input is read from stdin and has three parts:

  1. The first line contains an integer \(n\) — the number of elements in the array.
  2. The second line contains \(n\) space-separated integers representing the array.
  3. The third line contains an integer \(T\) — the target sum.

outputFormat

Output a single line to stdout that is either True if there exists a contiguous subarray summing to \(T\), or False otherwise.

## sample
5
1 2 3 7 5
12
True