#K69727. Count Subarrays With Given Sum
Count Subarrays With Given Sum
Count Subarrays With Given Sum
Given an array A of n integers and an integer S, the task is to count the number of contiguous subarrays whose sum is equal to S. In mathematical terms, find the number of pairs (l, r) such that
\( \sum_{i=l}^{r} A_i = S \)
This problem can be solved efficiently using prefix sums and hashing techniques. Make sure your solution reads from stdin and writes to stdout.
inputFormat
The input is given from stdin in the following format:
- The first line contains two integers n and S, where n is the number of elements in the array and S is the target sum.
- The second line contains n space-separated integers representing the array A.
outputFormat
Output a single integer on stdout representing the number of contiguous subarrays such that their sum is equal to S.
## sample5 5
1 2 3 4 5
2