結果
問題 |
No.617 Nafmo、買い出しに行く
|
ユーザー |
![]() |
提出日時 | 2018-03-02 13:35:38 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,399 bytes |
コンパイル時間 | 207 ms |
コンパイル使用メモリ | 12,288 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2025-01-02 20:17:32 |
合計ジャッジ時間 | 1,925 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 WA * 4 |
ソースコード
# -*- 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()