Project Panoptes
InterviewTime limit2sMemory limit512 MB
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 and let be the brightness on day . Let be the average of all readings. Day is dim when . The comparison is strict, so a day whose brightness equals exactly 80% of the average is not dim.
An integer is a period when both of these hold.
- There is a start day with and such that every one of that is at most is a dim day.
The second condition means two things. A period needs at least two dim days, so never exceeds . A subset is also not enough: if days 4, 7 and 10 are dim, then with still fails unless days 1 and 13 are dim as well.
Find the smallest period.
Input
The first line contains two integers and (, ), where is the number of observations and is the smallest period to consider.
Each of the next lines contains one real number (), 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.