D. Walking Robot

D. Walking Robot

time limit per test

2 seconds

memory limit per test

256 megabytes


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 

5 2 1
0 1 0 1 0

output 

5

input 

6 2 1
1 0 0 1 0 1

output 

3

Note

In the first example the robot can go through the first segment using the accumulator, and charge levels become b=2b=2 and a=0a=0. The second segment can be passed using the battery, and charge levels become b=1b=1 and a=1a=1. The third segment can be passed using the accumulator, and charge levels become b=1b=1 and a=0a=0. The fourth segment can be passed using the battery, and charge levels become b=0b=0 and a=1a=1. And the fifth segment can be passed using the accumulator.

In the second example the robot can go through the maximum number of segments using battery two times and accumulator one time in any order.

 

题意:

有n段路, 每段路有两种状态,有阳光和没阳光。没阳光要耗费一单位电量,a,b都可以消耗。  当有阳光时在a电池电量不满的情况下。可以消耗b的电量走过阳光区,同时又可以给a电池充一单位的电。当a 电池的电满时就不能充电了。

b, a的初始值就是这两种电池的容量。

 

 

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <map>
#include <set>
#include <cassert> 
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
const ll mod = 1e9+7;
const int N = 1e6; 

ll n,m,k;	ll ans=0;
int a,b;
int s[200005];

int main() {
	cin>>n>>b>>a;
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	int A=a,B=b;
	for(int i=1;i<=n;i++){
		if( s[i-1]== 1){
			if(a==A){
				a--;
			}
			else if(b>0){
				b--;
				a++;
			}
			else if(b<=0&&a>0){
				a--;
			}
			else if(a<=0&&b<=0){
				cout<<i-1;
				return 0;
			}
		}
		else{
			if(a>0)a--;
			else if(b>0) b--;
			else{
				cout<<i-1;
				return 0;
			}
		}
	} 
	cout<<n;
	return 0; 
} 
    
	

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值