Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 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

Qiita Conference 2025 will be held!: 4/23(wed) - 4/25(Fri)

Qiita Conference is the largest tech conference in Qiita!

Keynote Speaker

ymrl、Masanobu Naruse, Takeshi Kano, Junichi Ito, uhyo, Hiroshi Tokumaru, MinoDriven, Minorun, Hiroyuki Sakuraba, tenntenn, drken, konifar

View event details
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?