Michal, soon aged 23, is thinking of having a birthday party with his friends.
He typically likes to follow a schedule which consists of Physical and
Mental activities. In particular, he enjoys Working out (P),
Hiking (P), Reading books (M), and learning a new Language
(L). However, Michal is unsure what schedule he should make for the 28-th,
his birthday, since he wants to see this friends at 18:00, so he’s limited to a
12-hour schedule this time (he typically has an alarm set to 6AM).
Fortunately or not, he struggles to focus on one activity at a time. He
thereby usually switches from an activity to another every 30 minutes.
However, he ain’t no robot! If he is focused for 2 hours straight (he can
never do 5 activities in a row), he needs to take a break (also 30 minutes)
immediately afterwards.
At the end of the day, he creates a table and assigns a score (based on the
enjoyment gained) to each activity. In his opinion, reading books is the
coolest, so he assigns a +3 to it. He also enjoys sports, so either physical
activity makes up for a +2. Lastly, while learning a new language is rewarding,
it’s also difficult; +1 for the last one. However, Michal has noticed that if
he takes on a physical activity and then studies a language right
afterwards, he can focus better, so it isn’t as difficult as it usually tends
to be, and he enjoys it much more! Then he receives +2 extra scores. Lastly,
since Michal is motivated, he wants to minimize his breaks, so he receives 0
for each.
He recently read in an article that randomization isn’t too bad*. He
decided to write a QuickCheck generator that would create a schedule for him:
a sequence of 24 physical/ mental activities. But he wasn’t much
satisfied—the tool didn’t generate any breaks in between for him—so he’s
unsure when he shall rest (instead of doing some of the activities). Because
he’s still new to QuickCheck, he couldn’t fix the error, so he left the
generator unchanged, and decided to go with it.
Now Michal needs your help!
- Given: a sequence of 24 characters with each representing an activity
(i.e.,
W, H, R, L).
- Goal: insert breaks (
Bs) into the sequence and reach maximal
enjoyment (i.e., highest score) following the description above, so that
Michal will feel refreshed before seeing his friends. Print the maximal
score.
(the template can be obtained here)
Example
Input
Output
That is, \(2 + 1 + 2\) (bonus applied).
Input
Output
He rests instead of learning a language (L), so the sequence becomes
RRBRR, so he receives 3 for each R. He has rested enough.
Input
Output
He wants to boost his language learning, so he decides to work out, then study
Italian afterwards, the sequence becomes e.g. WWBWL. Then he receives \(2*2 + 2 + 1 + 2\), where the last \(2\) is the bonus which he didn’t want to miss.
[*]: https://pickowheel.com/blog/posts/the-psychology-of-randomness