Mathison and pangrams
All submissions for this problem are available.
Read problems statements in mandarin chinese, russian and vietnamese as well.
Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a pangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters from the local store in order to turn his text into a pangram.
However, each letter has a price and Mathison is not very rich. Can you help Mathison find the cheapest way to obtain a pangram?
The first line of the input file will contain one integer, T, representing the number of tests.
Each test will be formed from two lines. The first one contains 26 space-separated integers, representing the prices of all letters. The second will contain Mathison's initial text (a string of N lowercase letters).
The output file will contain T lines, one for each test. Each line will contain the answer for the corresponding test.
Constraints and notes
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 50,000
- All prices are natural numbers between 1 and 1,000,000 (i.e. 106).
- A pangram is a string that contains every letter of the Latin alphabet at least once.
- All purchased letters are added to the end of the string.
Subtask #1 (30 points):
- N = 1
Subtask #2 (70 points):
- Original constraints
Input: 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 abcdefghijklmopqrstuvwz 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 thequickbrownfoxjumpsoverthelazydog Output: 63 0
First test There are three letters missing from the original string: n (price 14), x (price 24), and y (price 25). Therefore the answer is 14 + 24 + 25 = 63. Second test No letter is missing so there is no point in buying something. The answer is 0.
|Tags||alexvaleanu, cakewalk, looping, ltime51|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.