시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB0000.000%

문제

In Homeric Epics there are $n$ different words numbered from $1$ to $n$. The $i$-th word appears $w_i$ times in the text. Allison wants to substitute the $i$-th word with a $k$-ary string $s_i$, satisfying the following constraint: for any $1 \le i,j \le n$, $i \ne j$, $s_i$ is not the prefix of $s_j$.

Allison wants to know how to choose $s_i$ so that the resulting text has minimum length. Under the assumption that the total length of the text is minimal, Allison wants to know what is the shortest possible length of the longest $s_i$.

A string is called a $k$-ary string if and only if its characters are in $\{0, 1, \dots, k-1\}$.

A string $s_1$ is said to be a prefix of $s_2$ if and only if there exists $1 \le t \le m$ such that $s_1 = s_2[1 \dots t]$ where $m$ is the length of $s_2$ and $s_2[1 \dots t]$ represents the substring of $s_2$ formed by the first $t$ characters.

입력

The first line of the input file contains two integers $n,k$ separated by one space, denoting there are $n$ words in total and we need to substitute the words with a $k$-ary string.

In the following $n$ lines, the $(i+1)$-th line has a nonnegative integer $w_i$ denoting the number of times the $i$-th word has occurred.

출력

The output consists of two lines. The first line is an integer denoting the minimum length of the Homeric Epics after substitution. The second line is an integer denoting the minimum length of the longest string $s_i$ given the total length is minimum.

제한

  • $3 ≤ n ≤ 100\,000$
  • $2 ≤ k ≤ 9$
  • $0 < w_i \le 10^{11}$

예제 입력 1

4 2
1
1
2
2

예제 출력 1

12
2

예제 입력 2

6 3
1
1
3
3
9
9

예제 출력 2

36
3