Write Word Quickly
All submissions for this problem are available.
Find the fastest way to type a word, given the word. You can skip total of T letters. Time needed to write a letter is given in an array with 26 integers depicting the time needed to type the alphabets. Index 0 will represent a, 1 will represent b, 2 will represent c till 25 representing z. Print the fastest time needed to write the word, after skipping T letters.
Note: Each letter must be treated distinctly, example, if word is aaa and you can skip 1 letter, then you should type aa and not skip all the a's.
Input description.Input will start will an integer N on newline representing the count of test case. Each case will contain a number T on a newline, representing total count of letters you can skip. Next line of each test case will contain 26 integers representing the array of time needed to write letters a to z. Next line of each test case will contain the word that you need to type.
OutputFor each test case print the desired outputs, each on a newline.
- 1 ≤ N ≤ 10
- 1 ≤ Time needed for each letter ≤ 300
- 1 ≤ Length of word ≤ 10
- 1 ≤ T ≤ length of given word
Input: 1 1 100 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 abac Output:
Example case 1. one a can be skipped, requiring time 105 to write the word.
|Tags||chandubaba, keteki, kqpm2016, sorting|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, 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, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions