結果

問題 No.50 おもちゃ箱
ユーザー はむ吉🐹
提出日時 2016-07-18 20:56:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,699 ms / 5,000 ms
コード長 744 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 75,624 KB
最終ジャッジ日時 2024-06-25 21:47:07
合計ジャッジ時間 17,789 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env pypy3

import itertools


IMPOSSIBLE = -1


def main():
    num_items = int(input())
    items = map(int, input().split())
    num_boxes = int(input())
    boxes_base = sorted(map(int, input().split()), reverse=True)
    ans = num_boxes + 1
    for items_perm in itertools.permutations(items):
        boxes = boxes_base[:]
        item_idx = box_idx = 0
        while item_idx < num_items and box_idx < num_boxes:
            if boxes[box_idx] >= items_perm[item_idx]:
                boxes[box_idx] -= items_perm[item_idx]
                item_idx += 1
            else:
                box_idx += 1
        ans = min(ans, box_idx + 1)
    print(ans if ans <= num_boxes else IMPOSSIBLE)


if __name__ == '__main__':
    main()
0