#P10721. [GESP202406 六级] 计算得分

[GESP202406 六级] 计算得分

Background

Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1154.

Problem Description

Xiao Yang wants to calculate the score of a string consisting of mm lowercase letters.

Xiao Yang sets a scoring sequence A=[a1,a2,,an]A=[a_1,a_2,\ldots,a_n] of nn positive integers. If a substring of the string is formed by concatenating k(1kn)k(1\leq k \leq n) copies of abc\texttt{abc} end to end, then it can gain a score of aka_k. Also, characters in the string cannot be counted repeatedly for scoring. The total score of the whole string is the sum of the scores of the scoring substrings.

For example, suppose the string is dabcabcabcabzabc\texttt{dabcabcabcabzabc}. All possible scoring methods are as follows:

  • d+abc+abcabc+abz+abc\texttt{d+abc+abcabc+abz+abc} or d+abcabc+abc+abz+abc\texttt{d+abcabc+abc+abz+abc}, where d\texttt{d} and abz\texttt{abz} do not score, and the total score is a1+a2+a1a_1+a_2+a_1.
  • d+abc+abc+abc+abz+abc\texttt{d+abc+abc+abc+abz+abc}, and the total score is a1+a1+a1+a1a_1+a_1+a_1+a_1.
  • d+abcabcabc+abz+abc\texttt{d+abcabcabc+abz+abc}, and the total score is a3+a1a_3+a_1.

Xiao Yang wants to know, for a given string, what the maximum total score is.

Input Format

  • The first line contains a positive integer nn, representing the length of the scoring sequence AA.

  • The second line contains nn positive integers, representing the scoring sequence AA.

  • The third line contains a positive integer mm, representing the length of the string.

  • The fourth line contains a string of mm lowercase letters.

Output Format

Output one integer, representing the maximum total score of the given string.

3
3 1 2
13
dabcabcabcabz

9

Hint

Sample Explanation

The best scoring method is d+abc+abc+abc+abz\texttt{d+abc+abc+abc+abz}, and the total score is a1+a1+a1a_1+a_1+a_1, which is 99 points in total.

Constraints

Subtask ID Percentage nn mm aia_i Special Property
11 20%20\% 20\le 20 105\le 10^5 1000\le 1000 For all i(1in)i(1 \le i \le n), there exists aiai+1a_i \ge a_{i+1}
22 40%40\% 3\le 3
33 20\le 20

For all testdata, it is guaranteed that 1n201\leq n\leq 20, 1m1051\leq m\leq 10^5, and 1ai10001\leq a_i\leq 1000.

Translated by ChatGPT 5