Goldman SachsOA #32
Threshold Alerts
简单可在线判题
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.
输入格式
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 one integer, the total number of alerts.
样例 1
输入:
3
4
8
2
2
2
2
5
5
5
8
输出:
2
样例 2
输入:
2
3
4
3
4
3
3
输出:
2
样例 3
输入:
1
5
4
5
6
4
7
输出:
2
样例说明
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.