結果
問題 | No.50 おもちゃ箱 |
ユーザー |
![]() |
提出日時 | 2025-03-19 05:18:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 996 ms / 5,000 ms |
コード長 | 533 bytes |
コンパイル時間 | 476 ms |
コンパイル使用メモリ | 82,284 KB |
実行使用メモリ | 76,340 KB |
最終ジャッジ日時 | 2025-03-19 05:18:37 |
合計ジャッジ時間 | 18,379 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 38 |
ソースコード
from itertools import permutations INF = 1 << 60 N = int(input()) A = list(map(int, input().split())) M = int(input()) B = list(map(int, input().split())) B.sort(reverse=True) def put(xs) -> int: p = 0 caps = [0] * M for x in xs: while p < M and caps[p]+x > B[p]: p += 1 if p == M: return -1 caps[p] += x return p+1 ans = INF for ps in permutations(A): res = put(ps) if res == -1: continue ans = min(ans, res) if ans == INF: print(-1) else: print(ans)