Logo
(追記) (追記ここまで)

33661번 - Nearest Nice Numbers 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 2048 MB27161161.111%

문제

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 $N$ options. Then, each problem type $i\in \{1,2,\dots ,N\}$ is assigned a number $x_i \in [0,1]$ based on what share of the votes it received. So, we must have $\sum_{i=1}^{N}{x_i=1}$.

Unfortunately, many of the $x_i$ 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 $x_i$ with an integer $f_i$ so that the fraction $\frac{f_i}{D}$ (for a given $D$) approximates $x_i$. You must pick the $f_i$ values in a way that minimizes $\sum_{i=1}^{N}{|D\cdot x_i - f_i|}$ and ensures that $\sum_{i=1}^{N}{f_i=D}$.

입력

The first line of input contains two integers $N$ (2ドル≤N≤10^5$) and $D$ (1ドル≤D≤10^9$) where $N$ is the number of problem types and $D$ is the denominator to use. Then $N$ lines follow, with line $i$ containing the single number $x_i$.

출력

Output the minimum possible value of $\sum_{i=1}^{N}{|D\cdot x_i- f_i|}$ over all choices of $f$. Answers with an absolute or relative error of at most 10ドル^{-6}$ will be accepted.

제한

예제 입력 1

3 100
0.3333333333
0.3333333333
0.3333333334

예제 출력 1

1.3333333200

예제 입력 2

2 1
0.01
0.99

예제 출력 2

0.0200000000

예제 입력 3

2 2
0.5
0.5

예제 출력 3

0.0000000000

예제 입력 4

2 3
0.5
0.5

예제 출력 4

1.0000000000

힌트

출처

University > University of Alberta Programming Contest > UAPC 2025 > Division 1 I번

University > University of Alberta Programming Contest > UAPC 2025 > Division 2 K번

  • 문제를 만든 사람: Noah Weninger
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /