結果

問題 No.2370 He ate many cakes
ユーザー titiatitia
提出日時 2023-07-04 05:21:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 741 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 78,400 KB
最終ジャッジ日時 2023-09-25 02:50:27
合計ジャッジ時間 4,362 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,240 KB
testcase_01 AC 72 ms
71,264 KB
testcase_02 AC 72 ms
71,392 KB
testcase_03 AC 250 ms
78,288 KB
testcase_04 AC 72 ms
71,512 KB
testcase_05 AC 70 ms
71,344 KB
testcase_06 AC 71 ms
71,308 KB
testcase_07 AC 71 ms
71,536 KB
testcase_08 AC 72 ms
71,332 KB
testcase_09 AC 71 ms
71,240 KB
testcase_10 AC 172 ms
77,588 KB
testcase_11 AC 240 ms
78,216 KB
testcase_12 AC 168 ms
77,684 KB
testcase_13 AC 243 ms
78,116 KB
testcase_14 AC 242 ms
78,340 KB
testcase_15 AC 254 ms
78,400 KB
testcase_16 AC 177 ms
77,508 KB
testcase_17 AC 258 ms
78,168 KB
testcase_18 AC 83 ms
75,804 KB
testcase_19 AC 86 ms
76,800 KB
権限があれば一括ダウンロードができます

ソースコード

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