結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー titiatitia
提出日時 2023-09-30 00:42:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 991 ms / 3,000 ms
コード長 575 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,808 KB
実行使用メモリ 16,008 KB
最終ジャッジ日時 2023-09-30 00:42:30
合計ジャッジ時間 9,738 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,784 KB
testcase_01 AC 16 ms
7,752 KB
testcase_02 AC 16 ms
7,832 KB
testcase_03 AC 16 ms
7,784 KB
testcase_04 AC 17 ms
7,848 KB
testcase_05 AC 16 ms
7,828 KB
testcase_06 AC 15 ms
7,924 KB
testcase_07 AC 991 ms
15,772 KB
testcase_08 AC 839 ms
15,980 KB
testcase_09 AC 804 ms
16,008 KB
testcase_10 AC 784 ms
15,644 KB
testcase_11 AC 701 ms
15,980 KB
testcase_12 AC 768 ms
15,872 KB
testcase_13 AC 855 ms
15,864 KB
testcase_14 AC 902 ms
15,724 KB
testcase_15 AC 853 ms
15,688 KB
testcase_16 AC 887 ms
15,820 KB
testcase_17 AC 16 ms
7,884 KB
testcase_18 AC 17 ms
7,812 KB
testcase_19 AC 16 ms
7,844 KB
testcase_20 AC 16 ms
7,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
A=[int(input()) for i in range(N)]

K=A[0]
B=A[1:]

B.sort()

OK=len(B)
NG=-1

while OK>NG+1:
    mid=(OK+NG)//2

    now=K+B[mid]
    C=B[:mid]+B[mid+1:]

    ind=0
    member=0
    for i in range(len(C)-1,-1,-1):
        while ind<i and C[ind]+C[i]<=now:
            ind+=1

        if ind<i and C[ind]+C[i]>now:
            member+=1
            ind+=1

    #print(mid,now,member,C)

    if member<M:
        OK=mid
    else:
        NG=mid

if OK==len(B):
    print(-1)
else:
    print(B[OK])
    
    
0