QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB

#23857. 鉛筆

統計

JOI 君は鉛筆を $N$ 本買うために近くの文房具店に行くことにした.

文房具店では鉛筆が一定の本数ずつのセットで売られている.セット $X$ は $A$ 本で $B$ 円,セット $Y$ は $C$ 本で $D$ 円である.

JOI 君はセット $X$ かセット $Y$ の一方を選び,選んだセットをいくつか購入する.両方のセットを購入することはできない.$N$ 本以上の鉛筆を得るために必要な金額の最小値を求めよ.

入力

入力は以下の形式で標準入力から与えられる.

N A B C D

出力

JOI 君が $N$ 本以上の鉛筆を手に入れるのに必要な金額の最小値を出力せよ.

制約

  • $1 \le N \le 1000$.
  • $1 \le A \le 1000$.
  • $1 \le B \le 1000$.
  • $1 \le C \le 1000$.
  • $1 \le D \le 1000$.

入出力例

入力例 1

10 3 100 5 180

出力例 1

360

解説

JOI 君は $10$ 本の鉛筆を入手したい.セット $X$ は $3$ 本で $100$ 円,セット $Y$ は $5$ 本で $180$ 円である.この時,セット $X$ を選んだ場合は,セットを $4$ つ購入する必要があり $400$ 円必要である.セット $Y$ を選んだ場合は,セットを $2$ つ購入する必要があり $360$ 円必要である.したがって,必要な金額の最小値は $400$ 円と $360$ 円の小さい方で $360$ 円である.

入力例 2

6 2 200 3 300

出力例 2

600

解説

このとき,セット $X$ を選んだ場合もセット $Y$ を選んだ場合も必要な金額は $600$ 円である.必要な金額の最小値は $600$ 円である.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.