#P2717. Consecutive Subarray Average

    ID: 15981 Type: Default 1000ms 256MiB

Consecutive Subarray Average

Consecutive Subarray Average

Given a sequence of n positive integers \( \{a_i\}_{i=1}^{n} \) representing the fatigue values for each homework assignment and an integer threshold \( k \), your task is to count the number of continuous subarrays whose average is at least \( k \).

In other words, count the number of pairs \( (i, j) \) with \( 1 \le i \le j \le n \) such that:

[ \frac{a_i+a_{i+1}+\cdots+a_j}{j-i+1} \ge k ]

This condition can be reformulated by subtracting \( k \) from each element, leading to the equivalent requirement:

[ (a_i-k) + (a_{i+1}-k) + \cdots + (a_j-k) \ge 0 ]

Help zzs determine the number of such subarrays.

inputFormat

The first line contains two integers \( n \) and \( k \) (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) separated by a space.

The second line contains \( n \) positive integers \( a_1, a_2, \dots, a_n \) separated by spaces.

outputFormat

Output a single integer representing the number of contiguous subarrays with an average value greater than or equal to \( k \).

sample

3 3
3 3 3
6