NOI '15 P4 - Homeric Epics

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

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.

Input Specification

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.

Output Specification

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.

Sample Input 1

4 2
1
1
2
2

Sample Output 1

12
2

Sample Input 2

6 3
1
1
3
3
9
9

Sample Output 2

36
3

Constraints

Test CasenkAdditional Constraintsw_i
1n=3k=20 < w_i \le 10^{11}
2n=5k=2
3n=16k=2All w_i are equal.
4n=1000k=2The w_i are generated uniformly at random.
5n=1000k=2
6n=100\,000k=2
7n=100\,000k=2All w_i are equal.
8n=100\,000k=2
9n=7k=3
10n=16k=3All w_i are equal.
11n=1001k=3All w_i are equal.
12n=99\,999k=4All w_i are equal.
13n=100\,000k=4
14n=100\,000k=4
15n=1000k=5
16n=100\,000k=7The w_i are generated uniformly at random.
17n=100\,000k=7
18n=100\,000k=8The w_i are generated uniformly at random.
19n=100\,000k=9
20n=100\,000k=9

Scoring

For each test case:

  • If only the first line is correct, 40\% of points will be awarded;
  • If both lines are correct, 100\% of points will be awarded.

Comments

There are no comments at the moment.