結果

問題 No.2370 He ate many cakes
ユーザー rlangevinrlangevin
提出日時 2023-10-17 22:57:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 514 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 201 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 78,488 KB
最終ジャッジ日時 2023-10-17 22:57:58
合計ジャッジ時間 4,896 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,480 KB
testcase_01 AC 37 ms
53,480 KB
testcase_02 AC 39 ms
53,480 KB
testcase_03 AC 259 ms
78,456 KB
testcase_04 AC 37 ms
53,484 KB
testcase_05 AC 39 ms
53,484 KB
testcase_06 AC 37 ms
53,484 KB
testcase_07 AC 37 ms
53,484 KB
testcase_08 AC 37 ms
53,484 KB
testcase_09 AC 36 ms
53,484 KB
testcase_10 AC 167 ms
77,200 KB
testcase_11 AC 514 ms
78,480 KB
testcase_12 AC 279 ms
77,204 KB
testcase_13 AC 268 ms
78,488 KB
testcase_14 AC 497 ms
78,468 KB
testcase_15 AC 468 ms
78,448 KB
testcase_16 AC 191 ms
77,200 KB
testcase_17 AC 305 ms
78,472 KB
testcase_18 AC 68 ms
75,556 KB
testcase_19 AC 66 ms
75,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
if N == 1:
    print(sorted([0, A[0]], reverse=True)[K - 1])
    exit()
    
B, C = A[:N//2], A[N//2:]
N, M = len(B), len(C)
N2, M2 = 1 << N, 1 << M
L1 = []
for s in range(N2):
    val = 0
    for i in range(N):
        if (s >> i) & 1:
            val += B[i]
    L1.append(val)
    
L2 = []
for s in range(M2):
    val = 0
    for i in range(M):
        if (s >> i) & 1:
            val += C[i]
    L2.append(val) 
L2.sort()

def check(m):
    cnt = 0
    for a in L1:
        cnt += M2 - bisect_left(L2, m - a)
    return cnt >= K
        
            
yes = -10 ** 12
no = 10 ** 12
while no - yes != 1:
    mid = (yes + no)//2
    if check(mid):
        yes = mid
    else:
        no = mid
        
print(yes)
0