結果
| 問題 |
No.50 おもちゃ箱
|
| コンテスト | |
| ユーザー |
ntuda
|
| 提出日時 | 2025-05-03 09:26:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 925 ms / 5,000 ms |
| コード長 | 693 bytes |
| コンパイル時間 | 866 ms |
| コンパイル使用メモリ | 82,560 KB |
| 実行使用メモリ | 76,212 KB |
| 最終ジャッジ日時 | 2025-05-03 09:26:51 |
| 合計ジャッジ時間 | 13,485 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
from itertools import permutations
N = int(input())
A = list(map(int,input().split()))
M = int(input())
B = list(map(int,input().split()))
B.sort(reverse = True)
ans = M + 1
for P in permutations(A,N):
j = 0
now = B[0]
f = True
for i in range(N):
if now >= P[i]:
now -= P[i]
else:
j += 1
if j < M:
now = B[j]
if now >= P[i]:
now -= P[i]
else:
f = False
break
else:
f = False
break
if f:
ans = min(ans,j + 1)
if ans == M + 1:
print(-1)
else:
print(ans)
ntuda