atcoder#ARC096D. [ARC096F] Sweet Alchemy
[ARC096F] Sweet Alchemy
Score : points
Problem Statement
Akaki, a patissier, can make kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut , Doughnut , Doughnut . In order to make one Doughnut , she needs to consume grams of Moto. She cannot make a non-integer number of doughnuts, such as doughnuts.
The recipes of these doughnuts are developed by repeated modifications from the recipe of Doughnut . Specifically, the recipe of Doughnut is a direct modification of the recipe of Doughnut .
Now, she has grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
- Let be the number of Doughnut that she makes. For each integer such that , must hold. Here, is a predetermined value.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum number of doughnuts that can be made under the condition.
3 100 1
15
10 1
20 1
7
She has grams of Moto, can make three kinds of doughnuts, and the conditions that must hold are and . It is optimal to make two Doughnuts , three Doughnuts and two Doughnuts .
3 100 10
15
10 1
20 1
10
The amount of Moto and the recipes of the doughnuts are not changed from Sample Input 1, but the last conditions are relaxed. In this case, it is optimal to make just ten Doughnuts . As seen here, she does not necessarily need to make all kinds of doughnuts.
5 1000000000 1000000
123
159 1
111 1
135 3
147 3
7496296