#P15590. [ICPC 2020 Jakarta R] Comic Binge
[ICPC 2020 Jakarta R] Comic Binge
Problem Description
A long vacation is coming! Andi and Budi, who are siblings, have just got a set of comic books as a gift from their uncle. As they had no plans for this vacation, they decided to stay home and read comic books.
There are comic books, numbered from 1 to . It takes hours for Andi to finish reading the book, while Budi needs hours to do so. Both Andi and Budi will read the comic books in ascending order of book number, one book at a time.
Because there is only one set of comic books, they decided to agree on the following rules:
- Budi, being the older brother, may skip one book after reading a book. More precisely, after Budi has finished reading the book, he may start reading the book without reading the book at all.
- If Budi does not skip the book, Andi, being the younger brother, is not allowed to start reading the book before Budi finished reading it. If Budi skips the book, there is no special condition for the book.
Both Andi and Budi must read the book and book to enjoy the storyline. Also, Andi wants to read all books, while Budi might skip some books according to the above rules. Andi and Budi are considered as finished reading the comic books if and only if both Andi and Budi have finished reading the book.
Your task in this problem is to determine the shortest time in hours for Andi and Budi to finish reading the comic books.
Input Format
Input begins with a line containing an integer: () representing the number of comic books. The second line contains integers: () representing the time in hours needed for Andi to read each book. The third line contains integers: () representing the time in hours needed for Budi to read each book.
Output Format
Output in a line an integer representing the shortest time in hours for Andi and Budi to finish reading the comic books.
6
3 1 1 1 1 2
1 5 3 3 7 4
13
2
2 1
1 1
4
Hint
Explanation for the sample input/output #1
The shortest time of hours can be achieved if Budi only read book , , , and . One possible reading schedule is as follows.
| Hour | Andi's reading | Budi's reading |
|---|---|---|
| 1 | Book 1 | |
| 2 | Book 1 | Book 3 |
| 3 | ||
| 4 | ||
| 5 | Book 2 | Book 4 |
| 6 | Book 3 | |
| 7 | ||
| 8 | Book 4 | Book 6 |
| 9 | ||
| 10 | Book 5 | |
| 11 | ||
| 12 | Book 6 | |
| 13 |
Explanation for the sample input/output #2
Both Andi and Budi have to read book and book . The shortest time for them to finish all the books is hours. One possible reading schedule is as follows.
| Hour | Andi's reading | Budi's reading |
|---|---|---|
| 1 | Book 1 | |
| 2 | Book 1 | |
| 3 | Book 2 | |
| 4 | Book 2 |