結果

問題 No.2370 He ate many cakes
ユーザー kutaragi36
提出日時 2023-07-03 23:27:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 450 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,660 KB
実行使用メモリ 78,176 KB
最終ジャッジ日時 2024-07-17 21:24:47
合計ジャッジ時間 4,154 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import itertools

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


def make(A):
    N = len(A)
    res = []
    for X in itertools.product((True, False), repeat=N):
        t = 0
        for a, x in zip(A, X):
            if x:
                t += a
        res.append(t)
    return res

X = make(A[:N//2])
Y = make(A[N//2:])

Y.sort()
ly = len(Y)

def f(z):
    #z以上がK個以上あるか
    cnt = 0
    for x in X:
        rem = z - x
        idx = bisect.bisect_left(Y, rem)
        cnt += ly - idx
    return cnt >= K
    

l = -10**9 *N
r = 10**9 * N + 1
while r - l > 1:
    m = (r + l) // 2
    
    if f(m):
        l = m
    else:
        r = m
print(l)
0