Maximum Score From Removing Substrings
You are given a string s and two integers x and y. You can perform two types of operations any number of times.
- Remove substring
"ab"and gainxpoints. - For example, when removing
"ab"from"cabxbae"it becomes"cxbae". - Remove substring
"ba"and gainypoints. - For example, when removing
"ba"from"cabxbae"it becomes"cabxe".
Return the maximum points you can gain after applying the above operations on s.
Example 1
Input
s = "cdbcbbaaabab", x = 4, y = 5Output
19Removing substrings in an optimal order gives a total score of 5 + 4 + 5 + 5 = 19.
Example 2
Input
s = "aabbaaxybbaabb", x = 5, y = 4Output
20The maximum score obtainable by removing
"ab" and "ba" substrings is 20.Constraints
- 1 <= s.length <= 10^5
- 1 <= x, y <= 10^4
- s consists of lowercase English letters.