結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー daikisuyamadaikisuyama
提出日時 2020-12-07 10:22:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,858 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 81,720 KB
実行使用メモリ 117,540 KB
最終ジャッジ日時 2023-10-17 16:00:11
合計ジャッジ時間 3,510 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,884 KB
testcase_01 AC 38 ms
53,628 KB
testcase_02 AC 39 ms
53,884 KB
testcase_03 AC 39 ms
53,628 KB
testcase_04 WA -
testcase_05 AC 39 ms
53,884 KB
testcase_06 AC 38 ms
53,628 KB
testcase_07 AC 127 ms
78,840 KB
testcase_08 AC 118 ms
78,852 KB
testcase_09 AC 99 ms
78,520 KB
testcase_10 AC 111 ms
88,312 KB
testcase_11 AC 131 ms
110,756 KB
testcase_12 AC 103 ms
78,548 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 39 ms
53,884 KB
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

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]
    for j in range(m):
        d=cand[j]+cand[-1-j]
        if d>c:
            return False
    return True
#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