結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー furafura
提出日時 2020-07-31 03:56:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 3,000 ms
コード長 554 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 203,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 17:40:36
合計ジャッジ時間 3,279 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 24 ms
4,376 KB
testcase_08 AC 24 ms
4,380 KB
testcase_09 AC 16 ms
4,376 KB
testcase_10 AC 15 ms
4,376 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 24 ms
4,376 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 21 ms
4,380 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	sort(a.begin()+1,a.end());
	int lo=0,hi=n;
	while(hi-lo>1){
		int mi=(lo+hi)/2;
		int a_mi=a[mi],sum=a[0]+a_mi;

		a.erase(a.begin()+mi);

		int cnt=0;
		for(int i=1,j=n-2;;i++,j--){
			while(i<j && a[i]+a[j]<=sum) i++;
			if(i>=j) break;
			cnt++;
		}
		if(cnt<m) hi=mi;
		else      lo=mi;

		a.insert(a.begin()+mi,a_mi);
	}
	printf("%d\n",hi==n?-1:a[hi]);

	return 0;
}
0