Unofficial Editorial for AtCoder Beginner Contest #185
Difference between en4 and en5, changed 286 character(s)
[Problem A](https://atcoder.jp/contests/abc185/tasks/abc185_a)↵
==============================================================↵

<spoiler summary="S
poilerolution">↵
Since we need exactly one of each of $A_1$, $A_2$, $A_3$ and $A_4$, we are limited by the minimum number we have of one of these. Therefore, we need to print the minimum element of these four.↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18767215)↵

</spoiler>↵

[Problem B](https://atcoder.jp/contests/abc185/tasks/abc185_b)↵
==============================================================↵

<spoiler summary="S
poilerolution">↵
If Takahashi's phone is to run out of battery during his walks between two of the locations, it will be at an even lesser battery at the end of that walk. So, we simply need to check that upon entering one of the $M$ cafes, or returning to his house, that his phone's battery is greater than 0, and increase his battery by $y_i-x_i$ for each of the cafes, while making sure the phone's battery is capped at $N$.↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18767149)↵

</spoiler>↵

[Problem C](https://atcoder.jp/contests/abc185/tasks/abc185_c)↵
==============================================================↵

<spoiler summary="S
poilerolution 1">↵
We can maintain a $dp_{i,j}$ where $i$ represents the number cuts made so far, and $j$ represents the length of the iron bar accounted for so far. The transitions are $dp_{i,j} = \sum_{k=0}^{j-1} dp_{i-1,k}$, and our answer is $dp_{12,n}$.↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18766806)↵

</spoiler>↵

[Problem D
<spoiler summary="Solution 2">↵

[See here
](https://atcoder.jp/contests/abc185/tasks/abc185_d)↵
==============================================================↵

<spoiler summary="Spoiler
forces.com/blog/entry/85555?#comment-732531)↵

[saarang123's implementation (warning: Python used)](https://atcoder.jp/contests/abc185/submissions/18740195)↵
</spoiler>↵

[Problem D](https://atcoder.jp/contests/abc185/tasks/abc185_d)↵
==============================================================↵

<spoiler summary="Solution
">↵
First, sort $A$, so that we have all the blue squares in increasing order. Now, note that the number of white squares between two blue squares is $A_{i+1}-A{i} - 1$. Since we don't need to paint any squares between two blue squares if they are consecutive, as there are none, our value of $k$ will be the minimum across all of the number of white squares between all blue squares that are non-zero, including the number of consecutive non-zero white squares before the first blue square and after the last blue square. Now that we have our value of $k$, we simply need to colour each of these consecutive blocks of white squares. If there are $x_i$ consecutive white squares, we can colour them all red in $\lceil \frac{x_i}{k} \rceil = \lfloor \frac{x_i+k-1}{k} \rfloor$↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18766766)↵

</spoiler>↵

[Problem E](https://atcoder.jp/contests/abc185/tasks/abc185_e)↵
==============================================================↵

<spoiler summary="S
poilerolution">↵
Let $dp_{i,j}$ be the minimum number of operations to convert the first $i$ elements of $A$ into the first $j$ elements of $B$. Clearly, we can convert the first $i$ elements of $A$ into the first $j$ elements of $B$ by simply deleting all $i+j$ elements. Now, we can recalculate our $dp$, in order of increasing {i+j}, as follows:↵

- If $A_i=B_j$: $dp_{i,j} = min(i+j, dp_{i-1,j-1}, dp_{i-1,j}+1, dp_{i,j-1}+1)$↵

- Otherwise: $dp_{i,j} = min(i+j, dp_{i-1,j-1}+1, dp_{i-1,j}+1, dp_{i,j-1}+1)$↵

This is because we can reduce the problem down, respectively, by:↵

1. deleting all $i+j$ elements↵
2. leaving the $i-th$ and $j-th$ elements as they are and taking any penalties for having non-equal elements↵
3. deleting the previous element from $A$↵
4. deleting the previous element from $B$↵

Our answer is $dp_{n,m}$.↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18766349)↵

</spoiler>↵

[Problem F](https://atcoder.jp/contests/abc185/tasks/abc185_f)↵
==============================================================↵

<spoiler summary="S
poilerolution">↵
We can use a data structure, such as a Fenwick tree, or segment tree, to process these queries. ↵

[My solution](https://atcoder.jp/contests/abc185/submissions/18742069)↵

</spoiler>↵

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en9 English ScarletS 2021-09-12 16:09:14 2 Tiny change: 'ncreasing {i+j}, as follo' -> 'ncreasing ${i+j}$, as follo'
en8 English ScarletS 2020-12-13 23:17:26 23 Tiny change: 'y solution](https://' -> 'y solution (using a Fenwick tree)](https://'
en7 English ScarletS 2020-12-13 23:16:53 169
en6 English ScarletS 2020-12-13 19:14:42 8 Tiny change: 'ssions/18742069)\n\n</spo' -> 'ssions/18769701)\n\n</spo'
en5 English ScarletS 2020-12-13 17:55:47 286 added s&b w/ python (ew) implementation
en4 English ScarletS 2020-12-13 17:38:59 16
en3 English ScarletS 2020-12-13 17:33:19 23
en2 English ScarletS 2020-12-13 17:29:50 474
en1 English ScarletS 2020-12-13 17:20:34 3612 Initial revision (published)