結果

問題 No.914 Omiyage
ユーザー O2MTO2MT
提出日時 2020-12-13 02:10:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 208 ms
コンパイル使用メモリ 81,612 KB
実行使用メモリ 85,520 KB
最終ジャッジ日時 2023-10-20 02:55:38
合計ジャッジ時間 2,376 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
85,260 KB
testcase_01 AC 128 ms
83,144 KB
testcase_02 AC 47 ms
59,252 KB
testcase_03 AC 122 ms
85,520 KB
testcase_04 AC 57 ms
63,868 KB
testcase_05 AC 40 ms
53,444 KB
testcase_06 AC 40 ms
53,444 KB
testcase_07 AC 40 ms
53,444 KB
testcase_08 AC 40 ms
53,444 KB
testcase_09 AC 40 ms
53,444 KB
testcase_10 AC 41 ms
53,444 KB
testcase_11 AC 42 ms
53,444 KB
testcase_12 AC 63 ms
72,904 KB
testcase_13 AC 108 ms
81,200 KB
testcase_14 AC 110 ms
82,884 KB
testcase_15 AC 41 ms
53,444 KB
testcase_16 AC 41 ms
53,444 KB
testcase_17 AC 58 ms
65,916 KB
testcase_18 AC 40 ms
53,444 KB
testcase_19 AC 41 ms
53,444 KB
testcase_20 AC 41 ms
53,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect
N,M,K = map(int,input().split())
A = []
for _ in range(N):
    a = list(map(int,input().split()))
    A.append(a)
N //= 2
B = A[N:]
A = A[:N]
ans = 0
l,r = [],[]
def perm(n,s,arr,h):
    global N
    if n == len(h):
        arr.append(s)
        return
    for a in h[n]:
        if s+a >= K:
            continue
        perm(n+1,s+a,arr,h)
perm(0,0,l,A)
perm(0,0,r,B)
r.sort()
if l == [] or r == []:
    print(-1)
    exit()
for i in l:
    b = bisect(r,K-i)
    if i+r[b-1] > K:
        continue
    ans = max(ans,i+r[b-1])
if ans == 0:
    print(-1)
else:
    print(K-ans)
0