結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー roarisroaris
提出日時 2019-11-08 15:29:50
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 201 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 87,104 KB
実行使用メモリ 182,600 KB
最終ジャッジ日時 2023-10-13 03:12:29
合計ジャッジ時間 4,229 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,280 KB
testcase_01 AC 73 ms
71,476 KB
testcase_02 AC 73 ms
71,528 KB
testcase_03 AC 74 ms
71,116 KB
testcase_04 AC 73 ms
71,472 KB
testcase_05 AC 75 ms
71,340 KB
testcase_06 AC 73 ms
71,260 KB
testcase_07 AC 193 ms
157,848 KB
testcase_08 AC 193 ms
176,296 KB
testcase_09 AC 178 ms
176,524 KB
testcase_10 AC 166 ms
145,516 KB
testcase_11 AC 163 ms
133,104 KB
testcase_12 AC 180 ms
176,628 KB
testcase_13 AC 201 ms
182,600 KB
testcase_14 AC 196 ms
176,944 KB
testcase_15 AC 196 ms
176,596 KB
testcase_16 AC 196 ms
176,472 KB
testcase_17 AC 71 ms
71,336 KB
testcase_18 AC 72 ms
71,308 KB
testcase_19 AC 72 ms
71,276 KB
testcase_20 AC 73 ms
71,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

def judge(x):
    p = a0+a[x]
    b = [a[i] for i in range(N-1) if i != x]
    pair = 0
    l, r = 0, N-3
    
    while l < r:
        if b[l]+b[r] >= p+1:
            pair += 1
            r -= 1
        
        l += 1

    return pair <= M-1
    
def binary_search():
    left, right = 0, N-2
    
    while left <= right:
        mid = (left+right)//2
        
        if judge(mid):
            right = mid-1
        else:
            left = mid+1
    
    return left

N, M = map(int, input().split())
a0 = int(input())
a = [int(input()) for _ in range(N-1)]
a.sort()

idx = binary_search()

if idx == N-1:
    print(-1)
else:
    print(a[idx])
0