Nearest Nice Numbers
시간 제한1초메모리 제한2048 MB
N개의 확률과 분모 D가 주어질 때, 합이 D인 정수 f_i를 골라 |D·x_i - f_i|의 합을 최소로 만든다.
문제
While typical programming contests try to strike a balance between different types of problems (geometry, graphs, dynamic programming, number theory, strings, etc), at the User-Aligned Programming Competition (UAPC), the contestants decide in advance what types of problems they want to see by voting in a survey. The survey format is simple: each contestant picks their single favorite type of problem among options. Then, each problem type is assigned a number based on what share of the votes it received. So, we must have .
Unfortunately, many of the values came back with an unsightly number of decimal places due to the extremely large number of survey responses, which is not suspicious at all. To fix this, your job is to replace each with an integer so that the fraction (for a given ) approximates . You must pick the values in a way that minimizes and ensures that .
입력
The first line of input contains two integers () and () where is the number of problem types and is the denominator to use. Then lines follow, with line containing the single number .
출력
Output the minimum possible value of over all choices of . Answers with an absolute or relative error of at most will be accepted.