結果

問題 No.914 Omiyage
ユーザー nadarenadare
提出日時 2019-10-25 21:32:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 613 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 82,340 KB
実行使用メモリ 81,796 KB
最終ジャッジ日時 2024-09-24 16:24:54
合計ジャッジ時間 2,447 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
from itertools import product
from bisect import bisect
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, M, K = inpl()
A = [inpl() for _ in range(N)]
ans = -1
h = N//2

L = []
for J in product(range(M), repeat=h):
    tmp = 0
    for i, j in enumerate(J):
        tmp += A[i][j]
    if tmp <= K:
        L.append(tmp)

L = sorted(L)

for J in product(range(M), repeat=N-h):
    tmp = 0
    for i, j in enumerate(J):
        tmp += A[i+h][j]
    r = bisect(L, K-tmp)
    if r:
        ans = max(ans, tmp+L[r-1])

print(K-ans if ans >= 0 else -1)
0