結果

問題 No.617 Nafmo、買い出しに行く
ユーザー kichirb3kichirb3
提出日時 2018-03-02 12:38:36
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 388 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 907 ms
コンパイル使用メモリ 10,880 KB
実行使用メモリ 53,524 KB
最終ジャッジ日時 2023-08-30 08:42:25
合計ジャッジ時間 5,021 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,292 KB
testcase_01 AC 16 ms
8,232 KB
testcase_02 AC 19 ms
8,468 KB
testcase_03 AC 32 ms
10,964 KB
testcase_04 AC 16 ms
8,400 KB
testcase_05 AC 51 ms
13,824 KB
testcase_06 AC 151 ms
53,496 KB
testcase_07 AC 149 ms
53,376 KB
testcase_08 AC 16 ms
8,232 KB
testcase_09 AC 16 ms
8,192 KB
testcase_10 AC 360 ms
53,492 KB
testcase_11 AC 360 ms
53,412 KB
testcase_12 AC 356 ms
53,492 KB
testcase_13 AC 363 ms
53,492 KB
testcase_14 AC 360 ms
53,488 KB
testcase_15 AC 375 ms
53,524 KB
testcase_16 AC 388 ms
53,400 KB
testcase_17 AC 370 ms
53,376 KB
testcase_18 AC 16 ms
8,336 KB
testcase_19 AC 16 ms
8,256 KB
testcase_20 AC 16 ms
8,252 KB
testcase_21 AC 16 ms
8,224 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(args):
    N, K = map(int, input().split())
    items = []
    for i in range(N):
        items.append(int(input()))

    itemsA = items[:10]
    itemsB = items[10:]

    totalA = []
    for i in range(2**len(itemsA)):
        mask = [int(x) for x in list(bin(i)[2:].zfill(len(itemsA)))]
        res = compress(itemsA, mask)
        totalA.append(sum(res))

    totalB = []
    for i in range(2**len(itemsB)):
        mask = [int(x) for x in list(bin(i)[2:].zfill(len(itemsB)))]
        res = compress(itemsB, mask)
        totalB.append(sum(res))

    grand_total = []
    for a in totalA:
        for b in totalB:
            grand_total.append(a+b)
    grand_total.sort()

    i = bisect_right(grand_total, K)
    print(grand_total[i-1])


if __name__ == '__main__':
    main(sys.argv[1:])
0