問題一覧 > 通常問題

No.3681 心の沸騰石

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 102
作問者 : 紫前燈太 / テスター : drken1215 ゆにたりー卿 Mikan04y lp_ql yimiya(いみや) よには 👑 loop0919 elphe Andrew8128 edon8618 👑 seekworser leaf_1415 triangle_coder 👑 みうね
お気に入りにしたユーザー ProblemId : 13395 / 自分の提出
問題文最終更新日: 2026-09-05 01:38:00
Boiling Stone of the Heart
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
第3回 岩井星人アンソロジープログラミングコンテスト (順位表) の他の問題:

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.
Here, the IWAtCoder users merged to create a Romanian in operation ${1}$ leave this place, and neither the Romanians created by operation ${1}$ nor Iwai Seijin are considered IWAtCoder users.

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