#P7996. [WFOI - 01] 硬币(coin)

    ID: 9086 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>数学二分洛谷原创O2优化洛谷月赛

[WFOI - 01] 硬币(coin)

Problem Description

In front of you there is a row of nn piles of coins in a line. Coins in the same pile have the same face value; denote the face value of the ii-th pile by aia_i. The number of coins in each pile is the same, denoted by xx.

Now you are given the face value aia_i of each pile. You need to determine a positive integer xx such that the variance of the total amount of money in each pile is closest to a positive integer kk.

Definition of “closest” between two numbers: the absolute value of their difference is minimal.

Variance definition: $s ^ 2 = \cfrac{(a_1 - \bar x)^2 + (a_2 - \bar x) ^ 2 + \cdots + (a_n - \bar x) ^ 2}{n}$, where xˉ\bar x represents the average of xx.

Input Format

The first line contains two integers n,kn,k.

The second line contains nn integers. The ii-th integer is aia_i, meaning the face value of the ii-th pile is aia_i.

Output Format

Output one positive integer on one line, representing the value of xx that satisfies the requirement. If there are multiple answers, output the smallest one. If no matter what value xx takes the variance is always 00, output one line No answer!.

7 47
7 2 4 6 3 7 10
3
4 4
4 4 4 4
No answer!

Hint

[Sample #1\#1 Explanation]

When x=3x=3, the amount of money in the ii-th pile is 3×ai3\times a_i. These amounts are 21,6,12,18,9,21,3021,6,12,18,9,21,30. The variance of these amounts is approximately 58.7858.78. It can be proven that when x=3x=3, the variance is closest to 4747.

[Sample #2\#2 Explanation]

It can be found that no matter what value xx takes, the variance will be 00, so output No answer!.

[Constraints]

This problem uses bundled Subtask testdata.

Subtask ID n,ain,\forall a_i\le kk\le Number of test points\footnotesize\texttt{Number of test points}
Subtask #0 (20pts)(20\texttt{pts}) 10310^3 10910^9 66
Subtask #1 (25pts)(25\texttt{pts}) 10510^5 101210^{12}
Subtask #2 (25pts)(25\texttt{pts}) 101810^{18}
Subtask #3 (30pts)(30\texttt{pts}) 7×1067\times10^6 3×10183\times 10^{18}

For 100%100\% of the testdata, 1n,ai7×1061\le n,\forall a_i\le7\times10^6, 1k3×10181\le k\le3\times10^{18}. Let the variance of the original array aa be pp. Then the testdata satisfies p=0p=0 or p[0.25, 2631]p\in[0.25,\ 2^{63}-1].

[Hint]

The input size of this problem is large. Please use a suitable input method. Here we recommend a fast input template. For C/C++\texttt{C/C++}, you can also use scanf to read input.

To avoid precision issues, C/C++\texttt{C/C++} users are advised to use type double\texttt{double}, and it is not recommended to use eps.

Translated by ChatGPT 5