Histogram

아직 제출이 없습니다시간 제한3초메모리 제한1024 MB

문제

For a range of \[1,n]\[1, n], the natural numbers in the interval are called the data values and let f_if\_i be the frequency count of the data value ii in the range. The frequency of a data value ii is the number of occurrences of the data value ii in the list of numbers. For example, the frequency of the data value 22 in the list \[3,2,3,2,4,2]\[3, 2, 3, 2, 4, 2] is 33. The following frequency table shows the frequency counts of the values in the range \[1,8]\[1, 8].

value ii12345678
frequency f_if\_i4236561216

A bucket b_ib\_i is represented by a range \[s_i,e_i]\[s\_i , e\_i] and its representative value r_ir\_i. For each bucket, we use the average frequency as the representative value. We want to represent the frequency table by a histogram that consists of a small number of buckets such that the intervals of the buckets do not overlap and cover the range of all data values in the frequency table. For example, a possible histogram of the above frequency table with two buckets is shown below where the first and second buckets cover the value range \[1,4]\[1, 4] and \[5,8]\[5, 8], respectively. In the histogram, the average frequencies of the first and second buckets are 3.753.75 and 9.759.75, respectively.

bucket interval\[1,4]\[1, 4]\[5,8]\[5, 8]
average frequency3.753.759.759.75

After a set of buckets from a frequency table is constructed, when the frequency of a value is asked, the average frequency of the bucket to which the value belongs should be answered. For instance, if the frequency of the value 22 is asked, since the value 22 belongs to the first bucket whose average frequency is 3.753.75, 3.753.75 will be answered instead of the true frequency 22 of the value 22. We define the error of a bucket in the histogram as the sum of the squared errors of the frequencies of all values in the bucket. In the above histogram, the error of the first bucket for the range \[1,4]\[1, 4] is (43.75)2(4 - 3.75)^2 ++ (23.75)2(2 - 3.75)^2 ++ (33.75)2(3 - 3.75)^2 ++ (63.75)2(6 - 3.75)^2 == 8.758.75 while that of the second bucket for the range \[5,8]\[5, 8] is (59.75)2(5 - 9.75)^2 ++ (69.75)2(6 - 9.75)^2 ++ (129.75)2(12 - 9.75)^2 ++ (169.75)2(16 - 9.75)^2 == 80.7580.75. The error of a histogram is then defined as the sum of the errors of all buckets in the histogram. Thus, the error of the histogram becomes 8.75+80.75=89.58.75 + 80.75 = 89.5. On the other hand, the following histogram has the error of 21.33333321.333333, that is the minimum among the errors of the histograms with two buckets.

bucket interval\[1,6]\[1, 6]\[7,8]\[7, 8]
average frequency4.3333334.3333331414

Given a frequency table and the number BB of buckets of the histogram, write a program that finds a minimum error histogram with at most BB buckets.

입력

Your program is to read from standard input. The input starts with a line containing an integer BB (1B301 \le B \le 30), where BB is the limit on the number of buckets. The second line contains an integer nn (1n4,0001 \le n \le 4,000) that is the number of data values, indicating the range \[1,n]\[1, n]. The next nn lines contain the frequencies of the data values. The ii-th line of them contains a positive integer that is the frequency f_if\_i of the data value ii, where 1f_i1001 \le f\_i ≤ 100.

출력

Your program is to write to standard output. Print exactly one line. The line should contain a real number zz that represents the error value OPTOPT of the histogram with a minimum error. The output zz should be in the format that consists of its integer part, a decimal point, and its fractional part, and it should satisfy the condition that OPT 104<z<OPT +104OPT - 10^{-4} < z < OPT + 10^{-4}.