AtlassianOA #2
Flower Bouquets
Estimated MediumJudge-ready
Topics (AI-labelled)DP Basics
In the row of flowers, 0 is a rose and 1 is a cosmos. Three consecutive roses 000 sell for p, and one rose and one cosmos adjacent as 01 or 10 sell for q. Each flower can be used at most once, some flowers may go unused, and removing flowers to splice together new adjacencies is not allowed.
Input
The first line contains p q, and the second line contains a binary string s. Original bounds: 1≤p,q≤1000, 1≤|s|≤100000.
Output
Output a single integer answer.
Example 1
Input:
2 3
0001000
Output:
5
Example 2
Input:
1 5
10
Output:
5
Example 3
Input:
9 1
000000
Output:
18
Example notes
The outputs of the three public examples are, in order: 5; 5; 18. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…