結果

問題 No.2370 He ate many cakes
ユーザー kutaragi36kutaragi36
提出日時 2023-07-03 23:27:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 464 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 79,476 KB
最終ジャッジ日時 2023-09-24 20:55:23
合計ジャッジ時間 4,969 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,184 KB
testcase_01 AC 76 ms
71,196 KB
testcase_02 AC 77 ms
71,524 KB
testcase_03 AC 464 ms
79,028 KB
testcase_04 AC 74 ms
71,216 KB
testcase_05 AC 75 ms
71,464 KB
testcase_06 AC 76 ms
71,436 KB
testcase_07 AC 74 ms
71,212 KB
testcase_08 AC 75 ms
71,396 KB
testcase_09 AC 74 ms
71,384 KB
testcase_10 AC 289 ms
78,972 KB
testcase_11 AC 451 ms
79,080 KB
testcase_12 AC 189 ms
79,264 KB
testcase_13 AC 262 ms
79,260 KB
testcase_14 AC 257 ms
79,020 KB
testcase_15 AC 445 ms
79,044 KB
testcase_16 AC 197 ms
78,824 KB
testcase_17 AC 265 ms
79,476 KB
testcase_18 AC 97 ms
76,860 KB
testcase_19 AC 97 ms
77,108 KB
権限があれば一括ダウンロードができます

ソースコード

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