#K84987. Counting Subarrays with Threshold

    ID: 36541 Type: Default 1000ms 256MiB

Counting Subarrays with Threshold

Counting Subarrays with Threshold

You are given an array of n integers and a threshold value \(T\). Your task is to count the number of contiguous subarrays that contain at least one element which is greater than or equal to \(T\).

A subarray is a continuous segment of the array. For example, if \(n = 5\), \(T = 3\) and the array is [1, 3, 2, 4, 2], then one valid subarray is [1, 3] because it contains the element 3 which is \(\ge T\). You should output the total count of such subarrays.

Input Format: Two lines of input. The first line contains two integers \(n\) and \(T\). The second line contains \(n\) space-separated integers representing the array.

Output Format: Print a single integer that is the count of subarrays satisfying the condition.

inputFormat

The input consists of two lines:

  1. The first line contains two integers (n) (the number of elements) and (T) (the threshold).
  2. The second line contains (n) space-separated integers representing the elements of the array.

outputFormat

Output a single integer: the total number of contiguous subarrays that contain at least one element (\ge T).## sample

5 3
1 3 2 4 2
12