#C2372. Find Contiguous Subarray Sum
Find Contiguous Subarray Sum
Find Contiguous Subarray Sum
Given an array and a target sum \( k \), determine if there exists a contiguous subarray whose elements sum exactly to \( k \). Formally, given an integer array \( \textbf{arr} \) with \( n \) elements, decide whether there exist indices \( i \) and \( j \) with \( 1 \leq i \leq j \leq n \) such that:
\( \sum_{t=i}^{j} arr_t = k \)
This problem can be efficiently solved by processing the prefix sum of the array and using a hash table to keep track of previously seen sums.
inputFormat
The input consists of two lines:
- The first line contains two integers \( n \) (the number of elements) and \( k \) (the target sum).
- The second line contains \( n \) space-separated integers representing the array \( arr \).
outputFormat
Output a single line containing YES if there exists a contiguous subarray whose sum is equal to \( k \), otherwise output NO.
## sample5 12
1 2 3 7 -3
YES