結果
問題 |
No.2730 Two Types Luggage
|
ユーザー |
![]() |
提出日時 | 2024-04-04 18:14:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 827 ms / 2,000 ms |
コード長 | 1,138 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 82,372 KB |
実行使用メモリ | 268,716 KB |
最終ジャッジ日時 | 2024-10-01 00:29:58 |
合計ジャッジ時間 | 19,681 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
# 入力 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<=n<=10**9)==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)