結果
問題 |
No.914 Omiyage
|
ユーザー |
![]() |
提出日時 | 2025-03-26 15:44:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 47 ms / 2,000 ms |
コード長 | 927 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 60,888 KB |
最終ジャッジ日時 | 2025-03-26 15:44:12 |
合計ジャッジ時間 | 1,831 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
n, m, k = map(int, input().split()) prices = [] min_sum = 0 for _ in range(n): row = list(map(int, input().split())) prices.append(row) min_sum += row[0] if min_sum > k: print(-1) else: dp = [False] * (k + 1) dp[0] = True # Initial state before considering any country for country in prices: new_dp = [False] * (k + 1) # Iterate through all possible sums up to k for j in range(k + 1): if dp[j]: for a in country: if j + a <= k: new_dp[j + a] = True # Check if there's any valid sum after processing this country if not any(new_dp): print(-1) exit() dp = new_dp # Find the maximum possible sum that does not exceed k max_sum = 0 for j in range(k, -1, -1): if dp[j]: max_sum = j break print(k - max_sum)