#K55022. Taco Subarray Sum
Taco Subarray Sum
Taco Subarray Sum
You are given an array of positive integers and a target sum \(K\). Your task is to determine whether there exists a continuous subarray (contiguous segment) of the given array whose elements sum exactly to \(K\). If such a subarray is found, output 1; otherwise, output 0.
Input Format: The input is read from standard input. The first line contains two integers \(n\) (the number of elements in the array) and \(K\) (the target sum). The second line contains \(n\) positive integers separated by spaces.
Output Format: Output a single integer 1 or 0 on standard output, representing whether a continuous subarray with sum equal to \(K\) exists.
Example:
Input: 5 8 1 3 5 23 2</p>Output: 1
The intended solution should work efficiently even for large arrays. Consider using cumulative sums along with a set (or hash table) to track previously seen sums.
inputFormat
The first line of input contains two integers \(n\) and \(K\), where \(n\) is the number of elements in the array and \(K\) is the target sum. The second line contains \(n\) space-separated positive integers, representing the array.
outputFormat
Output a single integer (either 1 or 0) to standard output. Output 1 if there exists a continuous subarray with sum equal to \(K\), otherwise output 0.
## sample5 8
1 3 5 23 2
1