CF1154D.Walking Robot

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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=1s_i = 1, otherwise si=0s_i = 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.

有一个机器人静止在 OxOx 轴上的 X=0X=0 处,它需要行进至 X=nX=n。你负责控制该机器人及其行进方式。机器人配备有一块电池和一个带太阳能板的蓄能器。

路径的第 ii 段(即从 X=i−1X=i-1 到 X=iX=i 的区间)可能暴露在阳光下,也可能不暴露。数组 ss 描述了各段是否暴露于阳光下:若第 ii 段暴露于阳光下,则 si=1s_i = 1;否则 si=0s_i = 0。

机器人拥有一块容量为 bb 的电池和一个容量为 aa 的蓄能器。对于每一段路径,你需选择机器人使用哪一种能量存储装置来行进至下一点(只能是电池或蓄能器)。若机器人使用电池行进,则当前电池电量减少 1(若电池电量为 0,则不可使用电池);若使用蓄能器行进,则当前蓄能器电量减少 1(若蓄能器电量为 0,则不可使用蓄能器)。

若当前路径段暴露于阳光下,且机器人使用电池通过该段,则蓄能器电量增加 1(当然,其电量不能超过最大容量 aa)。

若使用蓄能器通过某一段路径,则无论该段是否暴露于阳光下,蓄能器电量均减少 1。

你意识到,并非总能成功行进至 X=nX=n。你希望让机器人尽可能走得更远。请找出在最优控制下,机器人最多能够通过多少段路径。

输入格式

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

The second line of the input contains nn integers s1,s2,…,sns_1, s_2, \dots, s_n (0≤si≤10 \le s_i \le 1), where sis_i is 11 if the ii-th segment of distance is exposed to sunlight, and 00 otherwise.

输入的第一行包含三个整数 n,b,an, b, a(1≤n,b,a≤2⋅1051 \le n, b, a \le 2 \cdot 10^5),分别表示机器人的目标位置、电池容量和蓄能器容量。

输入的第二行包含 nn 个整数 s1,s2,…,sns_1, s_2, \dots, s_n(0≤si≤10 \le s_i \le 1),其中 si=1s_i = 1 表示第 ii 段距离暴露在阳光下,否则 si=0s_i = 0。

输出格式

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

输出一个整数——在你最优控制机器人的情况下,它能够通过的线段的最大数量。

输入输出样例

  • 输入#1

    5 2 1
    0 1 0 1 0

    输出#1

    5
  • 输入#2

    6 2 1
    1 0 0 1 0 1

    输出#2

    3

说明/提示

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.

在第一个例子中,机器人可以使用蓄电池通过第一段路径,此时电量变为 b=2b=2 和 a=0a=0;第二段路径可使用电池通过,电量变为 b=1b=1 和 a=1a=1;第三段路径可使用蓄电池通过,电量变为 b=1b=1 和 a=0a=0;第四段路径可使用电池通过,电量变为 b=0b=0 和 a=1a=1;第五段路径可使用蓄电池通过。

在第二个例子中,机器人最多可通过两段路径使用电池、一段路径使用蓄电池,且这三次使用顺序任意。

输入解题思路,AI测评打分。不知道怎么写?

首页