結果
| 問題 |
No.2370 He ate many cakes
|
| ユーザー |
chankei271828
|
| 提出日時 | 2023-07-04 00:50:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 817 ms / 2,000 ms |
| コード長 | 817 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 85,768 KB |
| 最終ジャッジ日時 | 2024-07-17 22:28:23 |
| 合計ジャッジ時間 | 6,069 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
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])
chankei271828