#GD0000132. Robot chạy bằng năng lượng mặt trời (Walking Robot)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Robot chạy bằng năng lượng mặt trời (Walking Robot)
Walking Robot
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A robot starts at position and wants to traverse unit segments. Its battery initially holds units and its solar accumulator initially holds units (both full). Every segment consumes one unit from exactly one source. When using the battery on a sunny segment , the accumulator recharges by one up to its capacity. Find the maximum number of traversable segments.
Input
The first line contains . The next line contains binary values .
Output
Print the maximum number of segments traversed.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
5 2 1
0 1 0 1 0
Output
5
Explanation
Use accumulator on segment , battery on sunny segment to recharge it, accumulator on , battery on sunny to recharge, and accumulator on . All five segments are traversed.