問題一覧 > 通常問題

No.1446 Hamburger Steak and Natto Rice

レベル : / AI推定難易度 : 650 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 173
作問者 : Lithops / テスター : shiomusubi496
お気に入りにしたユーザー ProblemId : 6078 / 自分の提出
問題文最終更新日: 2021-04-03 09:31:23
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
新入生プログラミングコンテスト 2021(昼の部) (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。