#K77767. Count Continuous Subarrays with Target Sum
Count Continuous Subarrays with Target Sum
Count Continuous Subarrays with Target Sum
You are given an array of n integers and an integer target T. Your task is to determine the number of continuous subarrays (subarrays with consecutive elements) whose elements sum up exactly to T.
More formally, given an integer array \(a_1, a_2, \ldots, a_n\) and an integer target \(T\), count the number of pairs \((i, j)\) with \(1 \leq i \leq j \leq n\) such that:
[ \sum_{k=i}^{j} a_k = T ]
Note: The array may contain negative numbers and zeros.
Your solution should read input from standard input (stdin
) and print the result to standard output (stdout
).
inputFormat
The input consists of three lines:
- The first line contains a single integer n representing the number of elements in the array.
- The second line contains n space-separated integers representing the array elements.
- The third line contains an integer T, the target sum.
outputFormat
Print a single integer representing the total number of continuous subarrays that sum to T.
## sample3
1 1 1
2
2