

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
から までの番号がついた 体のモンスターをあなたは飼っています.
あなたのモンスターを討伐するために勇者がやってきました. 勇者はこれから ターンかけてモンスターに攻撃を仕掛けます. ターン目には,勇者は以下のいずれかの行動を行います.
-
MP を 消費してモンスター を攻撃する. この行動は,モンスター がまだ生きており,かつ勇者の MP が 以上のときにのみ行える.
-
何もしない.
勇者が攻撃を行った場合,あなたはそれに対して以下のいずれかの行動を行います.
-
MP を 消費してモンスター を守る. この行動はあなたの MP が 以上のときにのみ行える.
-
何もしない.このとき,モンスター は死んでしまう.
最初のターンが始まる前の段階で,勇者の MP は ,あなたの MP は です. また,勇者もあなたも の値をすべて把握しています. このとき,以下の条件をみたす最大の整数 を求めてください.
- あなたが適切な戦略を取ることで,勇者がどのように行動したとしても, 体以上のモンスターを最後まで生存させることができる.
制約
- 入力される値はすべて整数.
入力
入力は以下の形式で標準入力から与えられる.
出力
答えを出力せよ.
入力例 1Copy
2 3 2 1 1 2 1
出力例 1Copy
1
あなたは 体以上のモンスターを必ず生存させることができます.
以下にありうる進行の一例を示します.
- ターン目: 勇者がモンスター を攻撃する.
- あなたは何もせず,モンスター が死ぬ.
- ターン目: 勇者がモンスター を攻撃する.
- あなたはモンスター を守る.
- ターン目: 勇者はなにもしない.
入力例 2Copy
2 6 3 2 1 1 1 2 2 2
出力例 2Copy
1
入力例 3Copy
100 1 1 1 100
出力例 3Copy
100
入力例 4Copy
6 20 16 5 5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2
出力例 4Copy
2
Score : points
Problem Statement
You keep monsters numbered to .
A hero has come to slay your monsters. He will take turns to attack the monsters. In the -th turn, he performs one of the following actions.
-
Consume MP to attack monster . This action can only be performed when monster is still alive and the hero has at least MP.
-
Do nothing.
If the hero attacks, you will respond by performing one of the following actions.
-
Consume MP to defend monster . This action can only be performed when you have at least MP.
-
Do nothing. The monster will die.
Before the first turn begins, the hero has MP, and you have MP. Both you and the hero know all values of , , , , and . Find the greatest integer that satisfies the following condition.
- By using an appropriate strategy, you can keep at least monsters alive no matter how the hero acts.
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
2 3 2 1 1 2 1
Sample Output 1Copy
1
You can always keep at least one monster alive.
Here is one possible progression.
- The first turn: The hero attacks monster .
- You do nothing, and monster dies.
- The second turn: The hero attacks monster .
- You defend monster .
- The third turn: The hero does nothing.
Sample Input 2Copy
2 6 3 2 1 1 1 2 2 2
Sample Output 2Copy
1
Sample Input 3Copy
100 1 1 1 100
Sample Output 3Copy
100
Sample Input 4Copy
6 20 16 5 5 6 1 3 2 1 4 3 2 4 1 4 4 6 3 3 5 2 2 2
Sample Output 4Copy
2