結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー fiordfiord
提出日時 2017-07-12 17:51:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 153 ms / 3,000 ms
コード長 722 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 82,384 KB
実行使用メモリ 82,608 KB
最終ジャッジ日時 2024-04-16 17:51:41
合計ジャッジ時間 2,800 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 38 ms
52,224 KB
testcase_02 AC 42 ms
52,736 KB
testcase_03 AC 38 ms
52,352 KB
testcase_04 AC 38 ms
52,224 KB
testcase_05 AC 39 ms
52,352 KB
testcase_06 AC 38 ms
52,096 KB
testcase_07 AC 122 ms
81,708 KB
testcase_08 AC 138 ms
82,608 KB
testcase_09 AC 121 ms
81,148 KB
testcase_10 AC 121 ms
81,152 KB
testcase_11 AC 122 ms
81,248 KB
testcase_12 AC 125 ms
81,248 KB
testcase_13 AC 153 ms
82,536 KB
testcase_14 AC 146 ms
82,500 KB
testcase_15 AC 152 ms
82,560 KB
testcase_16 AC 150 ms
82,480 KB
testcase_17 AC 39 ms
52,096 KB
testcase_18 AC 42 ms
52,224 KB
testcase_19 AC 37 ms
51,968 KB
testcase_20 AC 38 ms
52,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
n,m=map(int,input().split())
k=int(input())
a=[int(input()) for i in range(n-1)]
a.sort()
l=0
r=n-3
cnt=0
while l<r:
	while l<r and a[l]+a[r]<=a[n-2]+k:
		l+=1
	if l<r:
		l+=1
		r-=1
		cnt+=1
if cnt>=m:
	print(-1)
	sys.exit(0)
low=0
high=n-2
for i in range(30):
	mid=int((low+high)/2)
	l=0
	r=n-2
	cnt=0
	while l<mid and mid<r:
		while l<mid and a[l]+a[r]<=a[mid]+k:
			l+=1
		if l<mid:
			l+=1
			r-=1
			cnt+=1
	if l<mid:
		r=mid-1
		while l<r:
			while l<r and a[l]+a[r]<=a[mid]+k:
				l+=1
			if l<r:
				l+=1
				r-=1
				cnt+=1
	elif mid<r:
		l=mid+1
		while l<r:
			while l<r and a[l]+a[r]<=a[mid]+k:
				l+=1
			if l<r:
				l+=1
				r-=1
				cnt+=1
	if cnt>=m:
		low=mid
	else:
		high=mid
print(a[high])
0