On-Call
InterviewTime limit2sMemory limit512 MB
Count how many times an alert turns on given a stream of per-minute error counts, a high threshold U, a low threshold L, and a window length D.
- Level
Medium5 of 10
- Topics
- Simulation, Sliding window, Implementation, Array
- Solved
- No attempts yet
Problem
Fox Jiro works for a company that runs a social networking site for programmers. His duty is to recover the service as soon as possible when it becomes unavailable.
His predecessor developed a monitoring system that detects service unavailability based on the frequency of server error responses such as "502 Bad Gateway" and "503 Service Unavailable". The system records the frequency of server error responses per minute. If the frequency stays high for a while, an alert is triggered and Fox Jiro receives a phone call. After that, if the frequency stays low for a while, the alert is resolved.
In more detail, alerts are triggered and resolved as follows.
- Initially, no alert is triggered.
- An alert is triggered when no alert is triggered and the frequency of server error responses for each of the last consecutive minutes is greater than or equal to .
- The alert is resolved when the frequency of server error responses for each of the last consecutive minutes is less than or equal to .
Fox Jiro can receive compensation from the company according to the number of times he received phone calls due to the alerts. Last month he received so many phone calls that he forgot how many times the alerts were triggered. Your task is to count the number of alerts triggered based on the record of server error responses.
Input
The input consists of a single test case of the following format.
The first line consists of four integers , , , and . represents the length of the record of the frequency of server error responses. , , and are the settings that determine the behavior of the monitoring system as explained above. Here, and satisfy . and satisfy .
The second line consists of integers. The -th integer represents the frequency of server error responses that occurred in the -th minute. Each of the integers in the second line is between 0 and inclusive.
Output
Print the number of times the alerts were triggered in one line.