T514759 「KDOI-10」Bargain

题目背景

[Chinese Statement](https://www.luogu.com.cn/problem/T511668?contestId=200849). You must submit your code at the Chinese version of the statement. |Input|Output|Time Limit|Memory Limit| |:--:|:--:|:--:|:--:| |standard input|standard output|1.0 s|512 MiB| This problem has $25$ tests. The full score is $100$ points, and $4$ points per test.

题目描述

There is an integer $n$ consisting only of digits $1\sim 9$. You can do an arbitrary number of operations on $n$ (possibly zero): - Choose a digit of $n$ and delete it. Suppose the digit is $x$, this operation will cost $v_x$. Note that after this operation, the length of $n$ decreases by $1$, and the value of $n$ also changes; - Delete all the remaining digits of $n$. This operation will cost $n$. Find the minimum cost to delete all digits of $n$.

输入格式

输出格式

说明/提示

**Sample 1 Explanation** In the first test case, the optimal operations are: - Delete digit $2$ with a cost of $10$. After that, $n$ becomes $13$; - Delete digit $3$ with a cost of $10$. After that, $n$ becomes $1$; - Delete all the remaining digits of $n$ with a cost of $1$. The total cost is $10+10+1=21$. It can be shown that this is the minimum cost. In the second test case, the optimal operations are: - Delete the first digit $1$ with a cost of $2$. After that, $n$ becomes $121$; - Delete the last digit $1$ with a cost of $2$. After that, $n$ becomes $12$; - Delete digit $2$ with a cost of $1$. After that, $n$ becomes $1$; - Delete all the remaining digits of $n$ with a cost of $1$. The total cost is $2+2+1+1=6$. **Sample 2** See `bargain/bargain2.in` and `bargain/bargain2.ans` in the attachments. This sample satisfies the constraints of test $3\sim 6$. **Sample 3** See `bargain/bargain3.in` and `bargain/bargain3.ans` in the attachments. This sample satisfies the constraints of test $11$. **Sample 4** See `bargain/bargain4.in` and `bargain/bargain4.ans` in the attachments. This sample satisfies the constraints of test $17,18$. **Sample 5** See `bargain/bargain5.in` and `bargain/bargain5.ans` in the attachments. This sample satisfies the constraints of test $23\sim 25$. *** **Constraints** For all the tests, it is guaranteed that: - $1\le t\le 10$; - $1\le n< 10^{10^5}$; - For each $1\le i\le 9$,$1\le v_i\le 10^5$; - $n$ consists only of digits $1\sim 9$. | Test Id | $n