| Concurso de programación ANIEI 2023 |
|---|
| Finished |
Maria is solving a code puzzle to unlock an ancient treasure chest she found on a remote island. The puzzle is based on finding a special binary string called a "Beautiful Binary String." A Beautiful Binary String is a binary string with unique properties.
Maria has a partial binary string, but she needs to determine the maximum length of the Beautiful Binary String she can form, ensuring it complies with specific constraints. The string must have at most C0 '0's and at most C1 '1's, and it must not contain any substring consisting solely of '0's with more than M0 characters, or any substring consisting solely of '1's with more than M1 characters.
Given the values of C0, C1, M0, and M1, your task is to help Maria find the length of the largest Beautiful Binary String she can form.
The input consists of a single line containing four integers separated by a space: C0 $$$(0 \leq C0 \leq 10^6)$$$, C1 $$$(0 \leq C1 \leq 10^6)$$$, M0 $$$(0 \leq M0 \leq 10^6)$$$, and M1 $$$(0 \leq M1 \leq 10^6)$$$.
Print a single integer, which is the length of the largest Beautiful Binary String that can be formed. If it is not possible to form a Beautiful Binary String, print -1.
10 10 10 10
20
10 1 1 1
3
2 2 3 3
4
| Name |
|---|


