LoginSignup
0
1

More than 3 years have passed since last update.

はじめに

前回
6日目です。昨日のコンテストのCに惨敗したtax_freeです。

#6

問題

考えたこと
Aピザ、Bピザ、ABピザの組合せの最小値を求める問題です。for文でABの枚数を指定して最小値を更新していく手法で解きました。

a, b, c, x, y = map(int,input().split())

price = a * x + b * y
for i in range(max(x,y)+1):
    price = min(price,c * 2 * i + max(a * (x - i),0) + max(b * (y - i),0))

print(price)

ABピザを0枚買ったときの値段を初期値にして、forで回しています。pythonのforはstop値-1で止まるので、+1するのを忘れるとサンプルケース3のように全部ABを買う場合が通りません。

c * 2 * i + max(a * (x - i),0) + max(b * (y - i),0))

x < i or y < iのときに、a * (x - i)、b * (y - i)が負になることを防ぐためにmax(0,計算結果)を取って負にならないようにしています。

まとめ

このくらいのCはできるようになったのかな。本番のコンテストでもこれくらい解けるようになりたい
では、また

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1