cswork / OAOpen practice workspace

Goldman SachsOA #32

Threshold Alerts

EasyJudge-ready

Topics (AI-labelled)Two PointersPrefix & Ranges

A compliance system monitors call volume. Whenever the average call volume over the most recent few minutes exceeds a threshold, it raises an alert. Let precedingMinutes=k. At time T (counting from 1), take the call volumes at the k times T−(k−1), T−(k−2), …, T and compute their average; raise one alert if the average is strictly greater than alertThreshold. When T<k there is not enough data, and no alert is raised.

Given the call volume of each minute, find the total number of alerts raised over the whole period.

Input

The first line contains precedingMinutes; the second line alertThreshold; the third line n; then n lines, each containing an integer numCalls[i], the call volume in minute i+1. 1≤precedingMinutes≤n, 1≤alertThreshold≤10^5, 1≤n≤10^5, 0≤numCalls[i]≤10^5.

Output

Output one integer, the total number of alerts.

Example 1

Input:

3
4
8
2
2
2
2
5
5
5
8

Output:

2

Example 2

Input:

2
3
4
3
4
3
3

Output:

2

Example 3

Input:

1
5
4
5
6
4
7

Output:

2

Example notes

Example 1: k=3, threshold 4, numCalls=[2,2,2,2,5,5,5,8]. At T=3 the average is (2+2+2)/3=2; the averages for T=4..8 are 2,3,4,5,6 in turn, and the last two exceed 4, for 2 alerts in total (an average equal to 4 raises no alert). Example 2: k=2, threshold 3; the averages are 3.5,3.5,3 in turn, and the first two exceed 3, for 2 alerts. Example 3: with k=1 it is simply a minute-by-minute comparison; 6 and 7 exceed 5, for 2 alerts.

Editorial

Loading solution…