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

25080번 - Homeric Epics 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB52240.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

힌트

출처

Olympiad > National Olympiad in Informatics (China) > NOI 2015 4번

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

출처

대학교 대회

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

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