結果
| 問題 | No.50 おもちゃ箱 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-06-02 21:49:02 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,015 ms / 5,000 ms |
| コード長 | 671 bytes |
| 記録 | |
| コンパイル時間 | 317 ms |
| コンパイル使用メモリ | 84,864 KB |
| 実行使用メモリ | 81,536 KB |
| 最終ジャッジ日時 | 2026-05-10 15:08:48 |
| 合計ジャッジ時間 | 16,074 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
import itertools
import copy
N = int(input())
lsA = list(map(int,input().split()))
M = int(input())
lsB = list(map(int,input().split()))
lsB.sort(reverse=True)
lsp = itertools.permutations(lsA)
cnt = float('INF')
for p in lsp:
lsB1 = copy.copy(lsB)
for i in range(N):
f = False
for j in range(M):
if lsB1[j] >= p[i]:
lsB1[j] -= p[i]
f = True
break
if f == False:
break
if f:
ii = 0
for j in range(M):
if lsB1[j] != lsB[j]:
ii += 1
cnt = min(ii,cnt)
if cnt == float('INF'):
print(-1)
else:
print(cnt)