atcoder#ABC271C. [ABC271C] Manga
[ABC271C] Manga
Score : points
Problem Statement
Takahashi is going to read a manga series "Snuke-kun" in volumes. Initially, Takahashi has books of this series. The -th book is Volume .
Takahashi may repeat the following operation any number of (possibly zero) times only before he begins to read:
- Do nothing if he has or less books; otherwise, sell two of the books he has and buy one book of any volume instead.
Then, Takahashi reads Volume , Volume , Volume , , in order. However, when he does not have a book of the next volume to read, he stops reading the series (regardless of the other volumes he has).
Find the latest volume of the series that he can read up to. If he cannot read any, let the answer be .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
6
1 2 4 6 7 271
4
Before he begins to read the series, he may do the following operation: "sell books of Volumes and and buy one book of Volume instead." Then, he has one book each of Volumes , , , , and . If he then begins to read the series, he reads Volumes , , , and , then tries to read Volume . However, he does not have one, so he stops reading at this point. Regardless of the choices in the operation, he cannot read Volume , so the answer is .
10
1 1 1 1 1 1 1 1 1 1
5
Takahashi may have multiple books of the same volume. For this input, if he performs the following operations before he begins to read the series, he can read up to Volume , which is the maximum:
- Sell two books of Volume and buy a book of Volume instead.
- Sell two books of Volume and buy a book of Volume instead.
- Sell two books of Volume and buy a book of Volume instead.
- Sell two books of Volume and buy a book of Volume instead.
1
5
0
Takahashi cannot read Volume .