Under construction

Still being built. Things may change

Dolls

Interview

Time limit1sMemory limit512 MB

Summary
Given N numbers in a fixed order, find a contiguous segment of at least K numbers whose standard deviation is minimized, and output that standard deviation.
Level

Medium5 of 10

Topics
Brute force, Prefix sum, Math, Implementation
Solved
No attempts yet

Problem

The Kakao Friends store sells N kinds of dolls. Among the N dolls, some sell well and some do not, so the well-selling dolls are placed where many people can see them and the poorly selling dolls are placed where fewer people can see them. Two dolls placed close together therefore have similar sales figures.

One day, to decide on a good arrangement, the store surveyed several people about their preference for the dolls. The survey found the number of people who prefer each doll, and the arrangement of the dolls is to be decided from this.

Brian, who manages the Kakao Friends store, wants to place dolls in a particular spot, and he selects the dolls for that spot as follows:

  • First, he arranges the N distinct dolls in a line, one of each kind, so that similar dolls sit close together.
  • Then he selects dolls in K or more consecutive positions whose number of preferring people has the smallest standard deviation, and places them in the same spot.

Find the standard deviation of the numbers of preferring people for the selected dolls.

Given N numbers a1, a2, …, aN, statistics defines the (arithmetic) mean as (a1 + a2 + … + aN) / N. Let this be m. The variance is defined as ((a1 - m)2 + (a2 - m)2 + … + (aN - m)2) / N, and the standard deviation is the non-negative square root of the variance.

Input

The first line gives N and K. N is an integer from 1 to 500, and K is an integer from 1 to N.

The second line gives N integers, the number of people who prefer each doll in the order the dolls are lined up. Each number is a non-negative integer at most 106.

Output

Print the standard deviation of the numbers of preferring people for the selected dolls. A result is accepted only if its relative or absolute error compared with the true answer is at most 10-6.

Examples2

  1. Example 1

    Input
    5 3
    1 2 3 4 5
    Expected output
    0.81649658092
  2. Example 2

    Input
    10 3
    1 4 1 5 9 2 6 5 3 5
    Expected output
    0.94280904158