#C2327. Counting Subarrays with Average Below a Threshold
Counting Subarrays with Average Below a Threshold
Counting Subarrays with Average Below a Threshold
Aditya is an avid marathon runner who logs his daily marathon times over a period of N days. He now wants to analyze his performance by determining how many contiguous segments (subarrays) of his log have an average running time less than or equal to a target time T.
Formally, given an array B of N integers where each element represents the time (in minutes) for a day, you are to compute the number of contiguous subarrays such that:
\( \frac{\sum_{i=l}^{r} B_i}{(r-l+1)} \le T \)
This inequality can be rewritten in a more computation‐friendly manner as:
\( \sum_{i=l}^{r} B_i \le T \times (r-l+1) \)
Your task is to write a program that reads the input from standard input (stdin) and outputs the number of such subarrays to standard output (stdout).
inputFormat
The input is given in two lines:
- The first line contains two integers N and T, where N (1 ≤ N ≤ 105) is the number of days and T (1 ≤ T ≤ 105) is the target time.
- The second line contains N space-separated integers representing the array B (1 ≤ B[i] ≤ 105).
outputFormat
Output a single integer: the count of all contiguous subarrays for which the average running time is less than or equal to T.
## sample5 3
4 2 1 6 5
6
</p>