#P13229. [GCJ 2015 #3] Smoothing Window
[GCJ 2015 #3] Smoothing Window
题目描述
Adamma is a climate scientist interested in temperature. Every minute, she records the current temperature as an integer, creating a long list of integers: . (Adamma uses her own special temperature scale rather than a familiar one like Celsius or Kelvin, so it's possible for the values to be large and negative!) She often plots these temperatures on her computer screen.
This morning, she decided to compute a sliding average of this list in order to get a smoother plot. She used a smoothing window of size , which means that she converted the sequence of temperatures into a sequence of average temperatures: . Each is the average of the values . The original values were all integers, but some of the may be fractional.
Unfortunately, Adamma forgot to save the original sequence of temperatures! And now she wants to answer a different question -- what was the difference between the largest temperature and the smallest temperature? In other words, she needs to compute $\max \left\{x_{1}, \ldots, x_{\mathrm{N}}\right\}-\min \left\{x_{1}, \ldots, x_{\mathrm{N}}\right\}$. But she only has , and the smoothed sequence.
After some thinking, Adamma has realized that this might be impossible because there may be several valid answers. In that case, she wants to know the smallest possible answer among all of the possible original sequences that could have produced her smoothed sequence with the given values of and .
输入格式
The first line of the input gives the number of test cases, . test cases follow; each test case consists of two lines. The first line contains integers and separated by a space character. The second line contains integer values $\operatorname{sum}_{1}, \operatorname{sum}_{2}, \ldots, \operatorname{sum}_{\mathrm{N}-\mathbf{K}+1}$, separated by space characters. is given by .
输出格式
For each test case, output one line containing "Case #x: y", where is the test case number (starting from 1) and is the smallest possible difference between the largest and smallest temperature.
3
10 2
1 2 3 4 5 6 7 8 9
100 100
-100
7 3
0 12 0 12 0
Case #1: 5
Case #2: 0
Case #3: 12
提示
Sample Explanation
In Case #1, the smoothed sequence is:
The integer sequence that gives the smallest difference is:
Note that the sequence:
Would give the same smoothed sequence with a maximum difference of , but this is not a valid answer because the original temperatures are known to have been integers.
In Case #2, all we know is that the sum of the original values was . It's possible that all of the original values were exactly , in which case the difference between the largest and smallest temperatures would be , which is as small as differences get!
In Case #3, the original sequence could have been:
Sample Explanation
- The will be integers between -10000 and 10000, inclusive.
Small dataset(6 Pts)
- Time limit:
2405 seconds.
Large dataset(7 Pts)
- Time limit:
48010 seconds.