結果
| 問題 | No.825 賢いお買い物 | 
| コンテスト | |
| ユーザー |  lam6er | 
| 提出日時 | 2025-03-20 21:16:17 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 850 bytes | 
| コンパイル時間 | 179 ms | 
| コンパイル使用メモリ | 82,688 KB | 
| 実行使用メモリ | 75,892 KB | 
| 最終ジャッジ日時 | 2025-03-20 21:17:10 | 
| 合計ジャッジ時間 | 2,248 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 13 WA * 6 | 
ソースコード
a, b, c = map(int, input().split())
min_price = None
def sum_digits(x):
    return sum(map(int, str(x)))
for U in range(a + 1):
    for V in range(b + 1):
        S = U + 10 * V
        if S == 0:
            continue  # can't buy anything
        C_prime = c - (a + b - U - V)
        if C_prime < 0:
            continue
        # Find maximum x <= S-1 such that sum_digits(x) == C_prime
        # Iterate x from S-1 down to 0
        found = False
        for x in range(S-1, -1, -1):
            if sum_digits(x) == C_prime:
                found = True
                break
        if found:
            P = S - x
            if P <= 0:
                continue  # invalid price
            if (min_price is None) or (P < min_price):
                min_price = P
if min_price is not None:
    print(min_price)
else:
    print("Impossible")
            
            
            
        