Under construction

Still being built. Things may change

Project Panoptes

Interview

Time limit2sMemory limit512 MB

Summary
Given n brightness readings and a lower bound p, find the smallest k >= p such that some arithmetic progression with step k lands only on dim days, where dim means below 0.8 times the average; output -1 if none exists.
Level

Medium5 of 10

Topics
Array, Brute force, Implementation, Math
Solved
No attempts yet

Problem

Project Panoptes uses low cost robotic telescopes to gather observations and look for planets outside the solar system, called exoplanets. In this problem you write a simple version of the software that picks exoplanet candidates out of those observations.

The telescope records the brightness of one star once per day. A day whose brightness drops may be a day when a planet passed in front of the star. When the drops repeat at a fixed spacing, the star becomes a candidate for having an exoplanet.

Number the observation days 1 through nn and let xix_i be the brightness on day ii. Let m=(x1+⋯+xn)/nm = (x_1 + \dots + x_n) / n be the average of all readings. Day ii is dim when xi<0.8mx_i < 0.8m. The comparison is strict, so a day whose brightness equals exactly 80% of the average is not dim.

An integer kk is a period when both of these hold.

  • k≥pk \ge p
  • There is a start day ss with 1≤s≤k1 \le s \le k and s+k≤ns + k \le n such that every one of s,s+k,s+2k,…s, s+k, s+2k, \dots that is at most nn is a dim day.

The second condition means two things. A period needs at least two dim days, so kk never exceeds n−1n-1. A subset is also not enough: if days 4, 7 and 10 are dim, then k=3k = 3 with s=1s = 1 still fails unless days 1 and 13 are dim as well.

Find the smallest period.

Input

The first line contains two integers nn and pp (2≤n≤10002 \le n \le 1000, 1≤p≤n−11 \le p \le n-1), where nn is the number of observations and pp is the smallest period to consider.

Each of the next nn lines contains one real number xx (0.0≤x≤100.00.0 \le x \le 100.0), the brightness of that day. The days are given in order.

Output

Print the smallest period that satisfies the conditions. Print -1 if no such period exists.

Examples5

  1. Example 1

    Input
    15 2
    20.6
    21.0
    23.2
    12.0
    17.5
    22.2
    4.8
    25.9
    13.0
    12.2
    10.8
    22.9
    30.4
    8.6
    24.9
    
    Expected output
    5
    
  2. Example 2

    Input
    15 6
    20.6
    21.0
    23.2
    12.0
    17.5
    22.2
    4.8
    25.9
    13.0
    12.2
    10.8
    22.9
    30.4
    8.6
    24.9
    
    Expected output
    6
    
  3. Example 3

    Input
    2 1
    0.0
    0.0
    
    Expected output
    -1
    
  4. Example 4

    Input
    6 1
    100.0
    1.0
    100.0
    1.0
    100.0
    1.0
    
    Expected output
    2
    
  5. Example 5

    Input
    5 1
    10.0
    10.0
    10.0
    10.0
    10.0
    
    Expected output
    -1