#C11298. Minimum Deletion Cost to Avoid Repeating Letters

    ID: 40598 Type: Default 1000ms 256MiB

Minimum Deletion Cost to Avoid Repeating Letters

Minimum Deletion Cost to Avoid Repeating Letters

Given a string (s) and an array of integers (cost) where (cost[i]) denotes the cost of deleting the (i^{th}) character of (s), your task is to remove characters from (s) such that no two adjacent characters are the same while minimizing the total deletion cost.

For every sequence of consecutive duplicate characters, you should remove characters with the lower cost, ensuring that only one character remains from each block of duplicates.

For example, if (s = \texttt{abaac}) and (cost = [1, 2, 3, 4, 5]), by deleting the duplicate 'a' with the lower cost in the sequence "aa", the minimum cost is (3).

inputFormat

The input is read from standard input in the following format:
The first line contains a non-empty string (s).
The second line contains (n) space-separated integers, where (n) is the length of (s), representing the deletion cost for each character in (s).

outputFormat

Output a single integer representing the minimum total cost required to delete characters from (s) so that no two adjacent characters are identical.## sample

abaac
1 2 3 4 5
3