結果

問題 No.507 ゲーム大会(チーム決め)
コンテスト
ユーザー H3PO4
提出日時 2021-07-13 21:46:02
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 612 ms / 3,000 ms
コード長 567 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 396 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 18,648 KB
最終ジャッジ日時 2026-03-24 01:05:01
合計ジャッジ時間 7,673 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N, M = map(int, input().split())
A0 = int(input())
A = sorted(int(input()) for _ in range(N - 1))
l, r = -1, N - 1
while r - l > 1:
    m = (r + l) // 2
    am = A[m] + A0
    pair_l = 0
    ct = 0
    for pair_r in range(N - 2, -1, -1):
        if pair_r == m:
            continue
        while pair_l < pair_r and (A[pair_l] + A[pair_r] <= am or pair_l == m):
            pair_l += 1
        if pair_l >= pair_r:
            break
        pair_l += 1
        ct += 1
    if ct >= M:
        l = m
    else:
        r = m
ans = A[r] if r < N - 1 else -1
print(ans)
0