Walking Robot

There is a robot staying at X=0X=0 on the OxOx axis. He has to walk to X=nX=n. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.

The ii-th segment of the path (from X=i−1X=i−1 to X=iX=i) can be exposed to sunlight or not. The array ss denotes which segments are exposed to sunlight: if segment ii is exposed, then si=1si=1, otherwise si=0si=0.

The robot has one battery of capacity bb and one accumulator of capacity aa. For each segment, you should choose which type of energy storage robot will use to go to the next point (it can be either battery or accumulator). If the robot goes using the battery, the current charge of the battery is decreased by one (the robot can't use the battery if its charge is zero). And if the robot goes using the accumulator, the current charge of the accumulator is decreased by one (and the robot also can't use the accumulator if its charge is zero).

If the current segment is exposed to sunlight and the robot goes through it using the battery, the charge of the accumulator increases by one (of course, its charge can't become higher than it's maximum capacity).

If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.

You understand that it is not always possible to walk to X=nX=n. You want your robot to go as far as possible. Find the maximum number of segments of distance the robot can pass if you control him optimally.

Input

The first line of the input contains three integers n,b,an,b,a (1≤n,b,a≤2⋅1051≤n,b,a≤2⋅105) — the robot's destination point, the battery capacity and the accumulator capacity, respectively.

The second line of the input contains nn integers s1,s2,…,sns1,s2,…,sn (0≤si≤10≤si≤1), where sisi is 11 if the ii-th segment of distance is exposed to sunlight, and 00 otherwise.

Output

Print one integer — the maximum number of segments the robot can pass if you control him optimally.

Examples

input

Copy

5 2 1
0 1 0 1 0
output

Copy

5
input

Copy

6 2 1
1 0 0 1 0 1
output

Copy

3
思路:无光时,先消耗蓄电池,蓄电池没电时消耗电池,都没电结束;有光时,首先贪心,先看蓄电池是否是满的,满电先消耗蓄电池,让蓄电池尽可能的多使用,其次,如果蓄电池不是满的,看电池是否有电,先消耗电池,在消耗蓄电池,在消耗电池时,如果蓄电池不是满的,可以给蓄电池充电,都没电结束;这样直至循环结束。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int n,b,a,s[200005];
    int i,j,k,q;
    k=0;
    cin>>n>>b>>a;
    q=a;
    for(i=0;i<n;i++)
        cin>>s[i];
    for(i=0;i<n;i++)
    {
        if(s[i]==0)
        {
            if(a==0)
            {
                if(b==0)
                    break;
                else
                    b--;
            }
            else
                a--;
        }
        if(s[i]==1)
        {
            if(a==q)
                a--;
            else
            {
                if(b==0)
                {
                    if(a==0)
                        break;
                    else
                        a--;
                }
                else
                {
                    b--;
                    if(a<q)
                        a++;
                }
            }

        }
        k++;
    }
    cout<<k<<endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值