結果

問題 No.50 おもちゃ箱
ユーザー yaoshimaxyaoshimax
提出日時 2015-02-22 15:50:42
言語 Python2
(2.7.18)
結果
AC  
実行時間 15 ms / 5,000 ms
コード長 823 bytes
コンパイル時間 675 ms
コンパイル使用メモリ 6,624 KB
実行使用メモリ 6,128 KB
最終ジャッジ日時 2023-09-08 03:36:19
合計ジャッジ時間 2,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,916 KB
testcase_01 AC 14 ms
5,896 KB
testcase_02 AC 11 ms
6,016 KB
testcase_03 AC 11 ms
6,048 KB
testcase_04 AC 11 ms
5,960 KB
testcase_05 AC 14 ms
5,928 KB
testcase_06 AC 12 ms
6,020 KB
testcase_07 AC 12 ms
5,844 KB
testcase_08 AC 11 ms
6,020 KB
testcase_09 AC 11 ms
6,020 KB
testcase_10 AC 11 ms
5,944 KB
testcase_11 AC 11 ms
5,848 KB
testcase_12 AC 11 ms
5,880 KB
testcase_13 AC 11 ms
6,016 KB
testcase_14 AC 11 ms
5,840 KB
testcase_15 AC 11 ms
6,016 KB
testcase_16 AC 11 ms
5,900 KB
testcase_17 AC 14 ms
5,936 KB
testcase_18 AC 12 ms
5,848 KB
testcase_19 AC 15 ms
5,932 KB
testcase_20 AC 11 ms
5,848 KB
testcase_21 AC 13 ms
5,876 KB
testcase_22 AC 14 ms
6,060 KB
testcase_23 AC 13 ms
5,904 KB
testcase_24 AC 12 ms
6,020 KB
testcase_25 AC 11 ms
5,840 KB
testcase_26 AC 12 ms
5,884 KB
testcase_27 AC 12 ms
5,952 KB
testcase_28 AC 14 ms
6,000 KB
testcase_29 AC 14 ms
6,072 KB
testcase_30 AC 15 ms
6,060 KB
testcase_31 AC 11 ms
5,908 KB
testcase_32 AC 14 ms
6,000 KB
testcase_33 AC 15 ms
5,932 KB
testcase_34 AC 14 ms
6,004 KB
testcase_35 AC 14 ms
6,128 KB
testcase_36 AC 15 ms
5,996 KB
testcase_37 AC 15 ms
5,996 KB
testcase_38 AC 14 ms
5,988 KB
testcase_39 AC 14 ms
5,932 KB
testcase_40 AC 14 ms
5,924 KB
testcase_41 AC 14 ms
6,020 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(raw_input())
A=map(int,raw_input().split())
M=int(raw_input())
B=map(int,raw_input().split())
B.sort()
B.reverse()
dp=[(-1,-1) for i in range(1<<N)]
dp[0]=(0,0)

def rec(mask):
    global dp,N,A,M,B
    if dp[mask][0]!=-1:
        return dp[mask]
    a,b=100,100
    for i in range(N):
        if (mask&(1<<i)) != 0:
            nmask = mask-(1<<i)
            n_box,rest=rec(nmask)
            na,nb=100,100
            if rest >= A[i]:
                na,nb=n_box,rest-A[i]
            elif n_box<M and B[n_box] >=A[i]:
                na,nb=n_box+1,B[n_box]-A[i]
            else:
                na,nb=100,100
            if a > na or( a==na and  b < nb ):
                a,b=na,nb
    dp[mask]=(a,b)
    #print format(mask,'b'), a,b
    return a,b


a,b=rec( (1<<N)-1 )
if a >N:
    print -1
else:
    print a

0