Coffee Cup Combo
InterviewTime limit1sMemory limit1024 MB
Given a binary string marking which lecture halls have coffee machines, find the most lectures Jonna can stay awake in while carrying at most two cups.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Jonna is a university student who attends lectures every day. Most lectures are far too simple for an algorithmic expert such as Jonna, so she can stay awake during a lecture only while drinking coffee. She must drink exactly one cup of coffee during each lecture to stay awake.
Some lecture halls have coffee machines, where she can always get coffee. When Jonna leaves a lecture hall, she can carry at most two coffee cups to the following lectures (one in each hand). She cannot hold more than two coffee cups at any time.
Given which lecture halls have coffee machines, compute the maximum number of lectures during which Jonna can stay awake.
Input
The first line contains the integer (), the number of lectures Jonna attends.
The second line contains a string of length . The -th character is 1 if the -th lecture hall has a coffee machine, and 0 otherwise.
Output
Print one integer, the maximum number of lectures during which Jonna can stay awake.