No.3681 心の沸騰石
タグ : / 解いたユーザー数 102
作問者 :
drken1215
ゆにたりー卿
lp_ql
yimiya(いみや)
よには
👑
Andrew8128
leaf_1415
triangle_coder
👑 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. Show the original
Problem Statement
Iwai Seijin once had a Romanian rival in competitive programming.
Iwai Seijin called him "the boiling stone of my heart" and the two pushed each other to improve, but he has since retired from competitive programming.Feeling lonely, Iwai Seijin was gazing at his profile when a brilliant idea struck him.
The Romanian flag has the colors "blue", "yellow", and "red" arranged from left to right.
In other words, by merging a red coder, a yellow coder, and a blue coder, one Romanian can surely be synthesized!To fill the loneliness of having lost the boiling stone of his heart, Iwai Seijin called out to all sorts of people in order to synthesize many Romanians as replacements.
As a result, red coders, yellow coders, and blue coders gathered, along with green coders, who were not even invited.
Users of IWAtCoder, a competitive programming web service, are assigned a color according to their competitive programming skill.
The only ones present here are IWAtCoder users whose color is red, yellow, blue, or green, and Iwai Seijin. There are exactly ${A,\ B,\ C,\ D}$ IWAtCoder users whose color is red, yellow, blue, and green, respectively.
Iwai Seijin initially has a value called rating equal to ${R}$, and he can perform the following operations any number of times, ${0}$ or more, in any order. However, he cannot perform an operation that would make his rating less than ${0}$ after the operation. Each operation is one of the following ${2}$ types.
- Operation ${1}$ : Decrease the rating by ${P}$ and merge ${1}$ IWAtCoder user of each of the colors red, yellow, and blue to create ${1}$ Romanian.
- Operation ${2}$ : Decrease the rating by ${Q}$ and change the color of any ${1}$ IWAtCoder user present here.
Find the maximum number of Romanians Iwai Seijin can create.
Input
$R\ P\ Q$ $A\ B\ C\ D$
- $0 \leq R \leq 10^9$
- $ 1 \leq P,Q \leq 10^9 $
- $0 \leq A,B,C,D \leq 10^9$
- All input values are integers.
Output
Output the maximum number of Romanians Iwai Seijin can create.
Sample
Sample 1
Input
800 200 100 1 2 2 1
Output
2
First, perform operation ${2}$ to decrease the rating by ${100}$, changing ${1}$ green IWAtCoder user into ${1}$ red IWAtCoder user.
Then, perform operation ${1}$ ${2}$ times to decrease the rating by ${400}$ and create ${2}$ Romanians.
It is impossible to create ${3}$ or more Romanians, so output ${2}$.
Sample 2
Input
800 1200 1200 300 300 300 300
Output
0
Iwai Seijin does not have enough rating to perform any operation.
Sample 3
Input
800 800 800 1 1 1 0
Output
1
Iwai Seijin's rating becomes ${0}$, but it can't be helped.
Sample 4
Input
314159265 9 26 17781089 21082123 14498465 7071840
Output
18908650
He was able to create as many Romanians as the total population of Romania (2025). Now he is no longer lonely.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。