#K93382. Count Contiguous Subarrays with Target Sum

    ID: 38407 Type: Default 1000ms 256MiB

Count Contiguous Subarrays with Target Sum

Count Contiguous Subarrays with Target Sum

Given an array of integers and a target sum (S), your task is to count the number of contiguous subarrays whose elements sum up exactly to (S). A subarray is a contiguous part of the array. This problem requires an efficient solution with an optimal time complexity.

For example, given the array [1, 2, 3, 4, 5] with (S = 5), there are two subarrays that meet the condition: [2, 3] and [5].

inputFormat

The first line of input 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) integers separated by spaces representing the array elements.

outputFormat

Output a single integer which is the count of contiguous subarrays whose sum equals (S).## sample

5 5
1 2 3 4 5
2

</p>