Energy Tycoon
InterviewTime limit2sMemory limit256 MB
Place each offered one-slot or two-slot plant on an n-slot board, removing blocking plants when full, to maximize the total plant count summed over all turns.
- Level
Medium5 of 10
- Topics
- Greedy, Simulation
- Solved
- No attempts yet
Problem
Vasya is playing a turn-based strategy game called Energy Tycoon.
The rules are simple.
- The board has slots in a row.
- A power plant occupies one or two consecutive slots and produces one unit of energy.
- Every turn the game offers one new power plant, and you can place it on the board if you want to. If there is no room for it, you can remove any of the plants you built earlier.
- At the end of every turn, the game adds the energy produced by the plants standing on the board to the total score.
Vasya already knows which power plant he can build on each turn. What is the largest total score he can reach?
Input
The first line contains the number of slots ().
The second line contains a string . If the -th character of is 1, you can build a one-slot power plant on turn , and if it is 2, you can build a two-slot power plant on turn . The number of turns does not exceed 100000.
Output
Print the largest total score that can be achieved.