Alarmist
Time limit1sMemory limit128 MB
Given n samples and a window size w, compute the floor of each window average and report the difference between the largest and smallest average.
- Level
Easy3 of 10
- Topics
- Sliding window, Array, Implementation
- Solved
- No attempts yet
Problem
As an end-of-the-world alarmist, you are always looking for new data to support your doomsday theories. A common form of data is a series of scalar samples taken over time — for example, the outdoor temperature recorded once per second for a whole day, or the height of the tide measured once per minute for a month. Given such a sampling, you want to check whether the gap between the largest sample and the smallest sample is large, so that you can shout that the world has changed dramatically and is about to end.
The trouble is that such data sets often contain erroneous samples whose values are far too large or far too small, caused by transient failures in the measuring equipment. To make your claims more believable, you smooth out these bad values by computing a moving average.
Given a series of samples and a window size with , the moving average consists of values. The first value is the average of the first samples . The second value is the average of the same window shifted one step forward, i.e. the average of , and so on. For simplicity, round each value of the moving average down to the nearest integer that is less than or equal to it (the floor).
For each data set, report the difference between the maximum and the minimum value of its moving average.
Input
The first line contains the number of data sets. The data sets follow, each in the form below.
The first line of a data set contains two integers and : the number of samples and the window size, with and . The next line contains non-negative integers, the samples; each sample is at most .
Output
For each data set, output a line Data Set x:, where is the number of the data set (starting from 1). On the next line, output the absolute difference between the maximum and the minimum value of the moving average. Follow each data set with a blank line.