結果

問題 No.2370 He ate many cakes
ユーザー chankei271828chankei271828
提出日時 2023-07-04 00:50:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 931 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 88,012 KB
最終ジャッジ日時 2023-09-24 22:06:34
合計ジャッジ時間 7,725 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,268 KB
testcase_01 AC 74 ms
71,252 KB
testcase_02 AC 75 ms
71,428 KB
testcase_03 AC 439 ms
83,588 KB
testcase_04 AC 76 ms
71,104 KB
testcase_05 AC 78 ms
71,500 KB
testcase_06 AC 77 ms
71,368 KB
testcase_07 AC 76 ms
71,376 KB
testcase_08 AC 76 ms
71,260 KB
testcase_09 AC 77 ms
71,224 KB
testcase_10 AC 176 ms
81,332 KB
testcase_11 AC 280 ms
83,296 KB
testcase_12 AC 484 ms
81,020 KB
testcase_13 AC 727 ms
87,344 KB
testcase_14 AC 308 ms
83,360 KB
testcase_15 AC 931 ms
86,568 KB
testcase_16 AC 897 ms
83,156 KB
testcase_17 AC 929 ms
88,012 KB
testcase_18 AC 420 ms
79,220 KB
testcase_19 AC 85 ms
76,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heapify,heappop,heappush
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
N,K=mi()
A=li()
if N==1:
    ans=[0,A[0]]
    ans.sort(reverse=True)
    print(ans[K-1])
else:
    n=N//2
    m=N-n
    C=[]
    D=[]
    for bit in range(1<<n):
        cnt=0
        for i in range(n):
            cnt+=((bit>>i)&1)*A[i]
        C.append(cnt)
    for bit in range(1<<m):
        cnt=0
        for i in range(m):
            cnt+=((bit>>i)&1)*A[i+n]
        D.append(cnt)
    C.sort(reverse=True)
    D.sort(reverse=True)
    h=[(-(c+D[0]),i,0) for i,c in enumerate(C)]
    #print(h)
    heapify(h)
    for _ in range(K-1):
        a,b,c=heappop(h)
        if c!=(1<<m)-1:
            heappush(h,(-(C[b]+D[c+1]),b,c+1))
    print(-h[0][0])
0