結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
|
提出日時 | 2022-10-12 04:31:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 227 ms / 3,000 ms |
コード長 | 820 bytes |
コンパイル時間 | 420 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 125,700 KB |
最終ジャッジ日時 | 2024-06-25 22:23:01 |
合計ジャッジ時間 | 3,820 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
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])