No.1446 Hamburger Steak and Natto Rice
タグ : / 解いたユーザー数 173
作問者 :
shiomusubi496
Problem Statement
Lithops is the chef at a three-star restaurant. His cooking is renowned for being very delicious.
Today's lunch is a set of hamburger steak and natto rice. A lunch is made using exactly $1$ dish each of hamburger steak and natto rice. The same hamburger steak or natto rice cannot be used in multiple sets. Lithops has prepared $A$ dishes of hamburger steak and $B$ dishes of natto rice in advance.
Lithops wants to make as many lunches as possible using these dishes.
For this purpose, Lithops has built the "Hamburger Steak and Natto Rice Mutual Conversion Machine".
When $N$ dishes of hamburger steak are put into the "Hamburger Steak and Natto Rice Mutual Conversion Machine", those hamburger steaks disappear and $1$ dish of natto rice comes out instead. Similarly, when $M$ dishes of natto rice are put in, those natto rice dishes disappear and $1$ dish of hamburger steak comes out instead.
Find the maximum number of lunches that can be made by using this "Hamburger Steak and Natto Rice Mutual Conversion Machine" any number of times, $0$ or more.
Input
$A\ B\ N\ M$
- $1\leq A, B, N, M\leq 10^{18}$
- All inputs are integers.
Output
Output the maximum number of lunches that can be made.
Print a newline at the end.
Sample
Sample 1
Input
1 10 2 3
Output
3
Put $3$ dishes of natto rice into the "Hamburger Steak and Natto Rice Mutual Conversion Machine", and repeat this $2$ times. This results in $3$ dishes of hamburger steak and $4$ dishes of natto rice, so $3$ lunches can be made.
It is impossible to make $4$ or more lunches, so output $3$.
Sample 2
Input
60 10 21 121
Output
12
Sample 3
Input
137734418266269227 770038739817504238 253812456928708090 155625970401908842
Output
137734418266269231
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。