#Lutece1289. 喵哈哈村的编码
喵哈哈村的编码
Migrated from Lutece 1289 喵哈哈村的编码
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
编码特别的有趣,特别是在喵哈哈村里的编码。
因为喵哈哈村的对编码有一些特别的限制。
假设某一个编码为,其中表示这是编码中的第位。
那么在喵哈哈村中,它应该满足以下要求:
- 不应该超过,即编码的长度不超过
- 每一个位置的取值范围为
对于所有的编码而言,应该满足任意一个编码都不是另外一个编码的前缀。
现在你就需要在满足以上条件的情况下,构造出个编码,使得 最小。
即第个编码的长度。
Input
第一行两个整数 ,()
第二行个整数()
第三行个整数(}
保证的乘积大于等于
Output
一个整数,表示最小值是多少。
Samples
2 2
4 3
2 1
7
3 2
1 2 4
2 2
10
Note
第一个样例的两个编码为:{1},{2},答案就是4+3=7
第二个样例的三个编码为:{1,1},{1,2},{2},答案就是2*1+2*2+4 = 10
Resources
每周一题 div1