原题传送门
贪心模拟
分类讨论
- 如果蓄电池没电了,那么肯定走干电池,如果走到一条1线段,蓄电池电量可以+1
- 如果蓄电池还有电,那么如果干电池没电,或者下一条线段为0,又或者蓄电池目前满电,走蓄电池,否则才走干电池
Code:
#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
int n, a, b, c;
inline int read(){
int s = 0, w = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') w = -1;
for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
return s * w;
}
int main(){
n = read(), a = read(), c = b = read();
int ans = 1;
for (; ans <= n; ++ans){
int x = read();
if (!c){
if (x) ++c;
--a;
} else{
if (c == b || !x || !a) --c;
else{
--a;
if (x) ++c;
}
}
if (!a && !c || ans == n) break;
// printf("%d %d\n", a, c);
}
printf("%d\n", ans);
return 0;
}