結果

問題 No.617 Nafmo、買い出しに行く
ユーザー kichirb3kichirb3
提出日時 2018-03-02 13:35:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-08-30 22:17:49
合計ジャッジ時間 1,508 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,272 KB
testcase_01 AC 17 ms
8,292 KB
testcase_02 AC 19 ms
8,328 KB
testcase_03 WA -
testcase_04 AC 17 ms
8,200 KB
testcase_05 AC 20 ms
8,288 KB
testcase_06 AC 23 ms
8,356 KB
testcase_07 AC 23 ms
8,280 KB
testcase_08 AC 17 ms
8,196 KB
testcase_09 AC 16 ms
8,332 KB
testcase_10 AC 23 ms
8,356 KB
testcase_11 AC 23 ms
8,356 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 23 ms
8,340 KB
testcase_16 AC 23 ms
8,364 KB
testcase_17 AC 23 ms
8,360 KB
testcase_18 AC 17 ms
8,240 KB
testcase_19 AC 16 ms
8,292 KB
testcase_20 AC 16 ms
8,280 KB
testcase_21 AC 16 ms
8,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.617 Nafmo、買い出しに行く
https://yukicoder.me/problems/no/617

"""
import sys
from sys import stdin
from itertools import compress
from bisect import bisect_right
input = stdin.readline


def main():
    N, K = map(int, input().split())
    items = []
    for i in range(N):
        items.append(int(input()))

    # アイテムを半分に分ける (後半は空の可能性もあり)
    items_a = items[:10]
    items_b = items[10:]

    # 前半のアイテムを選択した場合の重さの組み合わせを列挙
    total_a = []
    for i in range(2**len(items_a)):
        mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_a)))]
        res = compress(items_a, mask)
        total_a.append(sum(res))

    # 後半のアイテムを選択した場合の重さの組み合わせを列挙
    total_b = []
    for i in range(2**len(items_b)):
        mask = [int(x) for x in list(bin(i)[2:].zfill(len(items_b)))]
        res = compress(items_b, mask)
        total_b.append(sum(res))

    # 前半と後半の重さの組み合わせから、K以内での最大値を求める
    total_a.sort();
    total_b.sort();
    total_max = 0;
    for a in total_a:
        i = bisect_right(total_b, K-a)
        total = a + total_b[i-1]
        if total <= K:
            total_max = total
    print(total_max)


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