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 gain `x` points.
- For example, when removing `"ab"` from `"cabxbae"` it becomes `"cxbae"`.
- Remove substring `"ba"` and gain `y` points.
- For example, when removing `"ba"` from `"cabxbae"` it becomes `"cabxe"`.
Return *the maximum points you can gain after applying the above operations on* `s`.
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 gain x points.
For example, when removing "ab" from "cabxbae" it becomes "cxbae".
Remove substring "ba" and gain y points.
For example, when removing "ba" from "cabxbae" it becomes "cabxe".
Return the maximum points you can gain after applying the above operations ons.
Example 1:
Input: {"s":"cdbcbbaaabab","x":4,"y":5}
Output: 19
Constraints:
1≤s.length≤105
1≤x,y≤104
s consists of lowercase English letters.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"s":"cdbcbbaaabab","x":4,"y":5}
"ab" is worth x = 4 and "ba" is worth y = 5. Removing one pair can destroy the other kind, so grab the pricier pair "ba" (5 points) everywhere first, then take "ab" (4 points) from what is left.