

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
ファーストフードチェーン「ピザアット」のメニューは「A ピザ」「B ピザ」「AB ピザ」の 種類です。A ピザと B ピザは全く異なるピザで、これらをそれぞれ半分に切って組み合わせたものが AB ピザです。A ピザ、B ピザ、AB ピザ 枚あたりの値段はそれぞれ 円、 円、 円です。
中橋くんは、今夜のパーティーのために A ピザ 枚と B ピザ 枚を用意する必要があります。これらのピザを入手する方法は、 ピザや ピザを直接買うか、AB ピザ 枚を買って A ピザ 枚と B ピザ 枚に組み替える以外にはありません。このためには最小で何円が必要でしょうか?なお、ピザの組み替えにより、必要な量を超えたピザが発生しても構いません。
制約
- 入力中のすべての値は整数である。
入力
入力は以下の形式で標準入力から与えられる。
出力
枚の A ピザと 枚の B ピザを用意するために必要な最小の金額を出力せよ。
入力例 1Copy
1500 2000 1600 3 2
出力例 1Copy
7900
AB ピザを 枚買って A ピザと B ピザ 枚ずつに組み替え、A ピザを 枚買い足すのが最適です。
入力例 2Copy
1500 2000 1900 3 2
出力例 2Copy
8500
A ピザ 枚と B ピザ 枚をそのまま買うのが最適です。
入力例 3Copy
1500 2000 500 90000 100000
出力例 3Copy
100000000
AB ピザを 枚買って A ピザと B ピザ 枚ずつに組み替えるのが最適です。A ピザが 枚余計にできますが、構いません。
Score : points
Problem Statement
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are yen, yen and yen (yen is the currency of Japan), respectively.
Nakahashi needs to prepare A-pizzas and B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
Constraints
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum amount of money required to prepare A-pizzas and B-pizzas.
Sample Input 1Copy
1500 2000 1600 3 2
Sample Output 1Copy
7900
It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.
Sample Input 2Copy
1500 2000 1900 3 2
Sample Output 2Copy
8500
It is optimal to directly buy three A-pizzas and two B-pizzas.
Sample Input 3Copy
1500 2000 500 90000 100000
Sample Output 3Copy
100000000
It is optimal to buy AB-pizzas and rearrange them into A-pizzas and B-pizzas. We will have more A-pizzas than necessary, but that is fine.