結果
| 問題 |
No.2370 He ate many cakes
|
| ユーザー |
rlangevin
|
| 提出日時 | 2023-10-17 22:57:52 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 406 ms / 2,000 ms |
| コード長 | 805 bytes |
| コンパイル時間 | 418 ms |
| コンパイル使用メモリ | 82,576 KB |
| 実行使用メモリ | 78,896 KB |
| 最終ジャッジ日時 | 2024-09-17 20:06:43 |
| 合計ジャッジ時間 | 3,920 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 16 |
ソースコード
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)
rlangevin