結果
| 問題 | No.50 おもちゃ箱 |
| コンテスト | |
| ユーザー |
rlangevin
|
| 提出日時 | 2023-09-01 12:17:34 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 175 ms / 5,000 ms |
| コード長 | 717 bytes |
| 記録 | |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 20,784 KB |
| 実行使用メモリ | 15,364 KB |
| 最終ジャッジ日時 | 2026-06-06 12:39:01 |
| 合計ジャッジ時間 | 7,009 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 |
ソースコード
N = int(input())
A = list(map(int, input().split()))
M = int(input())
B = list(map(int, input().split()))
B.sort(reverse=True)
inf = 10 ** 18
ans = inf
def dfs(L = [], now = 0):
global ans
if len(L) > len(B) or len(L) >= ans:
return
if now == N:
temp = []
for a in L:
temp.append(a)
temp.sort(reverse=True)
for i in range(len(temp)):
if temp[i] > B[i]:
return
ans = min(ans, len(temp))
return
for i in range(len(L)):
L[i] += A[now]
dfs(L, now + 1)
L[i] -= A[now]
L.append(A[now])
dfs(L, now + 1)
L.pop()
return
dfs()
print(ans) if ans != inf else print(-1)
rlangevin