CF1428G1.Lucky Numbers (Easy Version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The only difference is that in this version q=1 . You can make hacks only if all versions of the problem are solved.
Zookeeper has been teaching his q sheep how to write and how to add. The i -th sheep has to write exactly k non-negative integers with the sum ni .
Strangely, sheep have superstitions about digits and believe that the digits 3 , 6 , and 9 are lucky. To them, the fortune of a number depends on the decimal representation of the number; the fortune of a number is equal to the sum of fortunes of its digits, and the fortune of a digit depends on its value and position and can be described by the following table. For example, the number 319 has fortune F2+3F0 .
Each sheep wants to maximize the sum of fortune among all its k written integers. Can you help them?
输入格式
The first line contains a single integer k ( 1≤k≤999999 ): the number of numbers each sheep has to write.
The next line contains six integers F0 , F1 , F2 , F3 , F4 , F5 ( 1≤Fi≤109 ): the fortune assigned to each digit.
The next line contains a single integer q ( q=1 ): the number of sheep.
Each of the next q lines contains a single integer ni ( 1≤ni≤999999 ): the sum of numbers that i -th sheep has to write. In this version, there is only one line.
输出格式
Print q lines, where the i -th line contains the maximum sum of fortune of all numbers of the i -th sheep. In this version, you should print only one line.
输入输出样例
输入#1
3 1 2 3 4 5 6 1 57
输出#1
11
输入#2
3 1 2 3 4 5 6 1 63
输出#2
8
说明/提示
In the first test case, 57=9+9+39 . The three 9 's contribute 1⋅3 and 3 at the tens position contributes 2⋅1 . Hence the sum of fortune is 11 .
In the second test case, 63=35+19+9 . The sum of fortune is 8 .