codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1154D.md (2942B)


      1 Source: https://codeforces.com/problemset/problem/1154/D
      2 
      3 D. Walking Robot
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.
     22 
     23 The $i$-th segment of the path (from $X=i-1$ to $X=i$) can be exposed to sunlight or not. The array $s$ denotes which segments are exposed to sunlight: if segment $i$ is exposed, then $s_i = 1$, otherwise $s_i = 0$.
     24 
     25 The robot has one battery of capacity $b$ and one accumulator of capacity $a$. 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).
     26 
     27 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).
     28 
     29 If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.
     30 
     31 You understand that it is not always possible to walk to $X=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.
     32 
     33 Input
     34 
     35 The first line of the input contains three integers $n, b, a$ ($1 \le n, b, a \le 2 \cdot 10^5$) — the robot's destination point, the battery capacity and the accumulator capacity, respectively.
     36 
     37 The second line of the input contains $n$ integers $s_1, s_2, \dots, s_n$ ($0 \le s_i \le 1$), where $s_i$ is $1$ if the $i$-th segment of distance is exposed to sunlight, and $0$ otherwise.
     38 
     39 Output
     40 
     41 Print one integer — the maximum number of segments the robot can pass if you control him optimally.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 5 2 1
     49 0 1 0 1 0
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 5
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 6 2 1
     62 1 0 0 1 0 1
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 3
     69 ```
     70 
     71 Note
     72 
     73 In the first example the robot can go through the first segment using the accumulator, and charge levels become $b=2$ and $a=0$. The second segment can be passed using the battery, and charge levels become $b=1$ and $a=1$. The third segment can be passed using the accumulator, and charge levels become $b=1$ and $a=0$. The fourth segment can be passed using the battery, and charge levels become $b=0$ and $a=1$. And the fifth segment can be passed using the accumulator.
     74 
     75 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.