結果

問題 No.2730 Two Types Luggage
ユーザー kusirakusira
提出日時 2024-04-05 14:01:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 820 ms / 2,000 ms
コード長 1,139 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 268,812 KB
最終ジャッジ日時 2024-10-01 01:07:07
合計ジャッジ時間 15,645 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

# 入力
n,m,w = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

if((1<=n<=10**6)==False): print(-1)
if((1<=m<=20)==False): print(-1)
if((1<=w<=10**15)==False): print(-1)
# step2で行う処理のために前計算(Aを降順に並び替え累積和を取る。)
A.sort(reverse = True)
CA = [0]
for i in range(n):
    if((1<=A[i]<=10**9)==False): print(-1)
    CA.append(CA[-1] + A[i])

for i in range(m):
    if((1<=B[i]<=10**9)==False): print(-1)
    if((1<=C[i]<=10**9)==False): print(-1)
# step1. タイプBの荷物の選び方を全探索する。(bit全探索) 
ans = 0
for i in range(1<<m):
    # 選んだ荷物の総重量cと総価値v
    c = 0
    v = 0
    for j in range(m):
        # 選ぶ
        if(i >> j & 1):
            c += B[j]
            v += C[j]

    # タイプBのだけで総重量を超えたらパスする
    if(c > w): continue
    # step2. ナップザックの残りの容量でタイプAの荷物を詰めれるだけ詰める
    v += CA[min(w-c,  n)]
    # 答えの更新
    ans = max(ans,v)

# 出力
print(ans)
0