結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー lam6er
提出日時 2025-03-20 20:35:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 161 ms / 3,000 ms
コード長 640 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 107,184 KB
最終ジャッジ日時 2025-03-20 20:37:24
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
a = [int(input()) for _ in range(n)]
a0 = a[0]
others = sorted(a[1:])
total_others = len(others)

ans = -1
low = 0
high = total_others - 1

while low <= high:
    mid = (low + high) // 2
    x = others[mid]
    # Create B by removing x at mid position
    B = others[:mid] + others[mid+1:]
    S = a0 + x
    cnt = 0
    l = 0
    r = len(B) - 1
    while l < r:
        if B[l] + B[r] > S:
            cnt += 1
            l += 1
            r -= 1
        else:
            l += 1
    if cnt <= m - 1:
        ans = x
        high = mid - 1
    else:
        low = mid + 1

print(ans if ans != -1 else -1)
0