結果

問題 No.2370 He ate many cakes
ユーザー titia
提出日時 2023-07-04 05:21:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 181 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 149 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 77,264 KB
最終ジャッジ日時 2024-07-18 02:41:46
合計ジャッジ時間 2,561 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from bisect import bisect_left

N,K=map(int,input().split())
A=list(map(int,input().split()))

if N==1:
    if K==2:
        print(0)
    else:
        print(A[0])
    exit()

A.sort()

B=A[:N//2]
C=A[N//2:]

X=[0]

for b in B:
    Y=[]
    for x in X:
        Y.append(x+b)

    X=X+Y

X2=[0]
for b in C:
    Y=[]
    
    for x in X2:
        Y.append(x+b)

    X2=X2+Y

X.sort()
X2.sort()

OK=-40*10**9
NG=40*10**9

while OK<NG-1:
    mid=(OK+NG)//2

    count=0
    #count+=len(X2)-bisect_left(X2,mid)
    #count+=len(X)-bisect_left(X,mid)
    for x in X:
        count+=len(X2)-bisect_left(X2,mid-x)

    #print(mid,count)

    if count>=K:
        OK=mid
    else:
        NG=mid

print(OK)

    
0