結果
| 問題 |
No.617 Nafmo、買い出しに行く
|
| コンテスト | |
| ユーザー |
kichirb3
|
| 提出日時 | 2018-03-02 13:36:55 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 2,000 ms |
| コード長 | 1,415 bytes |
| コンパイル時間 | 304 ms |
| コンパイル使用メモリ | 12,160 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2025-01-02 20:25:13 |
| 合計ジャッジ時間 | 1,852 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 20 |
ソースコード
# -*- 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 = max(total, total_max)
print(total_max)
if __name__ == '__main__':
main()
kichirb3