#K591. Count Subarrays With Sum T

    ID: 30789 Type: Default 1000ms 256MiB

Count Subarrays With Sum T

Count Subarrays With Sum T

You are given an array of integers and an integer \( T \). Your task is to determine the number of contiguous subarrays (subarrays) that sum exactly to \( T \). A subarray is a contiguous part of the array.

Input Format: The first line contains two integers, \( n \) and \( T \), where \( n \) is the size of the array and \( T \) is the target sum. The second line contains \( n \) space-separated integers representing the elements of the array.

Output Format: Output a single integer representing the number of subarrays whose sum is exactly \( T \).

Example:

Input:
5 5
1 2 3 -2 2

Output: 2

</p>

inputFormat

The input is given from standard input (stdin) and consists of two lines:

  • The first line contains two integers \( n \) and \( T \): the number of elements in the array and the target sum.
  • The second line contains \( n \) space-separated integers representing the array.

outputFormat

The output should be produced to standard output (stdout) and consist of a single integer: the number of subarrays whose sum is exactly \( T \).

## sample
5 5
1 2 3 -2 2
2