結果

問題 No.914 Omiyage
ユーザー lam6er
提出日時 2025-03-20 21:05:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 690 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 61,708 KB
最終ジャッジ日時 2025-03-20 21:05:43
合計ジャッジ時間 1,989 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m, k = map(int, input().split())
countries = []
for _ in range(n):
    countries.append(list(map(int, input().split())))

min_sum = sum(row[0] for row in countries)
if min_sum > k:
    print(-1)
else:
    dp = [False] * (k + 1)
    dp[0] = True
    for country in countries:
        tmp = [False] * (k + 1)
        for prev_sum in range(k + 1):
            if dp[prev_sum]:
                for price in country:
                    new_sum = prev_sum + price
                    if new_sum <= k:
                        tmp[new_sum] = True
        dp = tmp
    max_sum = -1
    for s in range(k, -1, -1):
        if dp[s]:
            max_sum = s
            break
    print(k - max_sum)
0