結果

問題 No.914 Omiyage
ユーザー O2MT
提出日時 2020-12-13 01:31:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 428 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 90,868 KB
最終ジャッジ日時 2024-09-19 22:40:27
合計ジャッジ時間 6,529 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *
N,M,K = map(int,input().split())
A = []
for _ in range(N):
    a = list(map(int,input().split()))
    a.sort()
    A.append(a)
INF = 10**9
ans = 0

hq = [(-a,1) for a in A[0]]

while hq:
    i,j = heappop(hq)
    if j == N:
        ans = max(ans,-i)
        continue
    for a in A[j]:
        if -(i-a) > K:
            break
        heappush(hq,(i-a,j+1))
if ans == 0:
    print(-1)
else:
    print(K-ans)
0