結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー daikisuyamadaikisuyama
提出日時 2020-12-07 10:27:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 155 ms / 3,000 ms
コード長 1,923 bytes
コンパイル時間 182 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 117,440 KB
最終ジャッジ日時 2023-10-17 16:01:05
合計ジャッジ時間 2,959 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,720 KB
testcase_01 AC 40 ms
53,476 KB
testcase_02 AC 39 ms
53,720 KB
testcase_03 AC 40 ms
53,476 KB
testcase_04 AC 39 ms
53,720 KB
testcase_05 AC 39 ms
53,720 KB
testcase_06 AC 40 ms
53,476 KB
testcase_07 AC 120 ms
78,740 KB
testcase_08 AC 119 ms
78,740 KB
testcase_09 AC 101 ms
78,404 KB
testcase_10 AC 113 ms
88,576 KB
testcase_11 AC 134 ms
111,396 KB
testcase_12 AC 102 ms
78,420 KB
testcase_13 AC 152 ms
113,848 KB
testcase_14 AC 150 ms
111,692 KB
testcase_15 AC 150 ms
112,080 KB
testcase_16 AC 155 ms
117,440 KB
testcase_17 AC 40 ms
53,720 KB
testcase_18 AC 39 ms
53,720 KB
testcase_19 AC 39 ms
53,720 KB
testcase_20 AC 39 ms
53,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#二分探索
from operator import floordiv,truediv,truth,not_
from math import log
'''
domain:= 定義域が整数(0)or実数(1)
searchtype:= T→Fで最大値(0)かF→Tで最小値(1)か
f:= boolを返す関数(単調性が必要)(答えでtrueを返すように) 
l,r:= 探索範囲(l,rはsearchtypeの条件を満たすように)
eps:= 誤差(整数なら1,実数なら誤差指定による)
args:= fの引数(iterable)…f(i,args)という形にして展開する必要がある
'''
#答えはvalueに格納
class binary_search:
    def __init__(self,domain,searchtype,f,l,r,eps,args=None):
        self.domain=domain
        self.searchtype=searchtype
        self.f=f
        self.args=args
        self.l,self.r=l,r
        self.iter=int(log((r-l)/eps,2.0))+5
        self.op1=[floordiv,truediv][domain]
        self.op2=[not_,truth][searchtype]
        self.value=self.calc()
    def calc(self):
        for _ in range(self.iter):
            diff=self.op1(self.r-self.l,2)
            bisection=self.l+diff
            if self.op2(self.f(bisection,self.args)):
                self.r=bisection
            else:
                self.l=bisection
        return [self.l,self.r][self.searchtype]
n,m=map(int,input().split())
a=[int(input()) for i in range(n)]
b=a[0]
a=sorted(a[1:],reverse=True)
#得られない場合の処理に注意
#スコアの昇順に並べる
#i番目の人と組む,T→F
def f(i,args):
    c=b+a[i]
    if i>=2*m:
        cand=a[:2*m]
    else:
        cand=a[:i]+a[i+1:2*m+1]
    #全部じゃない、どれか一つでも下回ればOK
    for j in range(m):
        d=cand[j]+cand[-1-j]
        if d<=c:
            return True
    return False
#i=0でF,i=n-2でTの場合を先に除く
#n=2*mの場合も
if n==2*m:
    print(a[n-2])
    exit()
if not f(0,None):
    print(-1)
    exit()
if f(n-2,None):
    print(a[n-2])
    exit()
b=binary_search(0,0,f,0,n-1,1)
print(a[b.value])
0