#P2168. [NOI2015] 荷马史诗
[NOI2015] 荷马史诗
Description
Allison has recently become obsessed with literature. On a lazy afternoon, she likes to slowly sip a cappuccino and quietly read her beloved Homer’s Epic. However, the grand work composed of The Odyssey and The Iliad is just too long, so Allison wants to shorten it by using an encoding method.
In one Homer’s Epic, there are distinct words, numbered from to . The total number of occurrences of the -th word is . Allison wants to replace the -th word with a base- string such that the following condition holds:
For any , , we have: is not a prefix of .
Now Allison wants to know how to choose to minimize the length of the new Homer’s Epic after replacement. Among all choices that minimize the total length, she also wants to know the minimal possible value of the maximum length among all .
A string is called a base- string if and only if each of its characters is an integer between and inclusive.
A string is called a prefix of a string if and only if there exists such that . Here, is the length of , and denotes the string consisting of the first characters of .
Input Format
The first line contains positive integers , separated by a single space, indicating that there are types of words and base- strings are to be used for replacement.
The next lines: the -th line contains positive integer , indicating the number of occurrences of the -th word.
Output Format
Output consists of lines.
The first line contains integer, the minimal total length of Homer’s Epic after re-encoding.
The second line contains integer, the minimal possible value of the maximum length among all under the condition that the total length is minimized.
4 2
1
1
2
2
12
2
6 3
1
1
3
3
9
9
36
3
Hint
Sample Explanation
Sample 1 explanation
Let denote that is a base- string.
One optimal scheme: let replace the -st word, replace the -nd word, replace the -rd word, and replace the -th word. Under this scheme, the minimal encoded length is:
The maximum length of is .
A non-optimal scheme: let replace the -st word, replace the -nd word, replace the -rd word, and replace the -th word. Under this scheme, the minimal encoded length is:
The maximum length of is . Compared with the optimal scheme, the article length is the same, but the maximum codeword length is larger.
Sample 2 explanation
One optimal scheme: let replace the -st word, replace the -nd word, replace the -rd word, replace the -th word, replace the -th word, and replace the -th word.
Constraints
All testdata ranges and characteristics are as follows (all data satisfy ): | Test No. | Scale of | Scale of | Remarks | | :------: | :-----------: | :----------: | :-----: | | | | | | | | | ^ | ^ | | | | ^ | All are equal | | | | ^ | are uniformly random within the range | | | ^ | ^ | | | | | ^ | ^ | | | ^ | ^ | All are equal | | | ^ | ^ | | | | | | ^ | | | | ^ | All are equal | | | | ^ | ^ | | | | | ^ | | | | ^ | ^ | | | ^ | ^ | ^ | | | | | ^ | | | | | are uniformly random within the range | | | ^ | ^ | | | | ^ | | are uniformly random within the range | | | ^ | | | | | ^ | ^ | ^ |
Additional Tips
Contestants should use 64-bit integers for input, output, storage, and computation.
Scoring
For each test point:
- If the first line of the output is correct, you will receive of the score for that test point.
- If the entire output is correct, you will receive of the score.
Translated by ChatGPT 5
京公网安备 11011102002149号