結果
問題 |
No.2370 He ate many cakes
|
ユーザー |
![]() |
提出日時 | 2023-06-29 23:22:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 724 ms / 2,000 ms |
コード長 | 837 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 86,296 KB |
最終ジャッジ日時 | 2024-07-06 13:15:46 |
合計ジャッジ時間 | 5,647 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
from itertools import product from heapq import heappop, heappush # lst内ケーキの選び方すべてにおける嬉しさのリスト def H(lst): ret = [] for pro in product((0, 1), repeat=len(lst)): val = 0 for el, pr in zip(lst, pro): if pr: val += el ret.append(val) return ret N, K = map(int, input().split()) A = list(map(int, input().split())) mid = N // 2 A_left, A_right = A[:mid], A[mid:] C, D = H(A_left), H(A_right) D.sort(reverse=True) def f(i, j): return C[i] + D[j] hque = [] # タプル(-f(i,j),i,j)を入れる。 for i in range(len(C)): heappush(hque, (-f(i, 0), i, 0)) for _ in range(K - 1): m_val, i, j = heappop(hque) if j + 1 < len(D): heappush(hque, (-f(i, j + 1), i, j + 1)) m_val, i, j = heappop(hque) ans = -m_val print(ans)