Average Voodoo Doll Price
Time limit2sMemory limit64 MB
Count the contiguous runs of days whose average doll price is at least P.
- Level
Medium6 of 10
- Topics
- Prefix sum, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
Mirko has been buying voodoo dolls. He wants to buy as cheaply as possible, so he writes down the price of a doll every day. His price list holds the doll prices of the last days, and the price is the price of a doll days ago.
Mirko thinks the average price over a run of consecutive days is connected to the price on the next day. While testing that hunch he ran into another question. For a given , how many runs of consecutive days within the last days had an average doll price greater than or equal to ?
Two runs of consecutive days count as different when they start at different positions or end at different positions.
Input
The first line contains the sequence length . ()
The second line contains the prices . ()
The third line contains an integer . ()
Output
Print on the first line the number of consecutive runs whose average price is greater than or equal to .
Hint
In the first example the only run whose average is at least 3 is {3}.
In the second example the runs whose average is at least 2 are {1, 3}, {1, 3, 2}, {3}, {3, 2}, {2}.