#C5041. Subarray Sum Problem
Subarray Sum Problem
Subarray Sum Problem
You are given an array of integers and a target integer \( T \). Your task is to determine if there exists a contiguous subarray whose sum is exactly equal to \( T \). For example, if the array is [1, 2, 3, 4, 5] and \( T = 9 \), there is a contiguous subarray [2, 3, 4] whose sum equals 9.
The problem requires an efficient solution that can handle large arrays. Consider using a prefix sum technique combined with an appropriate data structure (such as a hash set) to achieve an optimal solution.
Note: The subarray must be contiguous. The input will be provided via standard input (stdin) and the result should be printed to standard output (stdout) as either "True" or "False".
inputFormat
The first line contains an integer \( n \) representing the number of elements in the array.
The second line contains \( n \) space-separated integers representing the elements of the array.
The third line contains an integer \( T \) representing the target sum.
outputFormat
Print "True" if there exists a contiguous subarray whose sum is equal to \( T \); otherwise, print "False".
## sample5
1 2 3 4 5
9
True