結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2022-10-12 04:31:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 263 ms / 3,000 ms
コード長 820 bytes
コンパイル時間 552 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 129,016 KB
最終ジャッジ日時 2023-09-08 05:08:46
合計ジャッジ時間 5,332 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 105 ms
72,836 KB
testcase_01 AC 103 ms
72,928 KB
testcase_02 AC 100 ms
72,900 KB
testcase_03 AC 102 ms
72,972 KB
testcase_04 AC 103 ms
72,964 KB
testcase_05 AC 104 ms
72,924 KB
testcase_06 AC 100 ms
72,908 KB
testcase_07 AC 167 ms
93,472 KB
testcase_08 AC 155 ms
87,320 KB
testcase_09 AC 261 ms
124,572 KB
testcase_10 AC 263 ms
127,136 KB
testcase_11 AC 252 ms
123,140 KB
testcase_12 AC 253 ms
123,276 KB
testcase_13 AC 261 ms
123,524 KB
testcase_14 AC 263 ms
127,176 KB
testcase_15 AC 263 ms
129,016 KB
testcase_16 AC 259 ms
122,936 KB
testcase_17 AC 101 ms
72,824 KB
testcase_18 AC 100 ms
72,856 KB
testcase_19 AC 100 ms
72,692 KB
testcase_20 AC 100 ms
72,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,M = map(int,input().split())
A = [int(input()) for _ in range(N)]
a0 = A[0]
A = A[1:]
A.sort()
A = [a0] + A
def is_ok(i):
    
    threshold = A[i]+A[0]
    X = []
    for j in range(1,N):
        if j!=i:
            X.append(A[j])
    X.sort(reverse=True)
    v = deque(X)
    cnt = 0
    while v:
        x = v.popleft()
        while v:
            y = v.pop()
            if x+y>threshold:
                cnt += 1
                break
            
    return cnt<M

if is_ok(1):
    print(A[1])
    exit()
if not is_ok(N-1):
    print(-1)
    exit()
y = N-1
x = 1
while y-x>1:
    mid = (y+x)//2
    if is_ok(mid):
        y = mid
    else:
        x = mid
print(A[y])
    
0