結果

問題 No.158 奇妙なお使い
ユーザー gew1fw
提出日時 2025-06-12 18:54:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,586 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,464 KB
実行使用メモリ 76,620 KB
最終ジャッジ日時 2025-06-12 18:55:05
合計ジャッジ時間 2,594 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 17 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

def get_max(a1000, a100, a1, D, shop_1000, shop_100, shop_1):
    max_total = -1
    best_state = None
    max_x = min(a1000, D // 1000)
    for x in range(max_x + 1):
        remaining = D - x * 1000
        if remaining < 0:
            continue
        max_y = min(a100, remaining // 100)
        for y in range(max_y + 1):
            rem = remaining - y * 100
            if rem < 0:
                continue
            if a1 >= rem:
                new_a1000 = a1000 - x + shop_1000
                new_a100 = a100 - y + shop_100
                new_a1 = a1 - rem + shop_1
                total = new_a1000 * 1000 + new_a100 * 100 + new_a1
                if total > max_total or (total == max_total and best_state is None):
                    max_total = total
                    best_state = (new_a1000, new_a100, new_a1)
    return max_total, best_state

a1000, a100, a1 = map(int, input().split())
Db = int(input())
B1000, B100, B1 = map(int, input().split())
Dc = int(input())
C1000, C100, C1 = map(int, input().split())

count = 0

while True:
    max_b, state_b = get_max(a1000, a100, a1, Db, B1000, B100, B1)
    max_c, state_c = get_max(a1000, a100, a1, Dc, C1000, C100, C1)
    
    if max_b == -1 and max_c == -1:
        break
    
    selected = False
    if max_b >= max_c:
        if max_b != -1:
            a1000, a100, a1 = state_b
            count += 1
            selected = True
    else:
        if max_c != -1:
            a1000, a100, a1 = state_c
            count += 1
            selected = True
    
    if not selected:
        break

print(count)
0