結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー vjudge1
提出日時 2025-02-23 10:24:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 22 ms / 3,000 ms
コード長 677 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 158,128 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-02-23 10:24:32
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 100010;
int n, m;
int a[N];
bool check(int mid)
{
	int t = a[mid] + a[1] + 1, res = 0;
	for (int l = 2, r = n; l < r;)
		if (l == mid) l ++ ;
		else if (r == mid) r -- ;
		else if (a[l] + a[r] >= t) res ++ , l ++ , r -- ;
		else l ++ ;
	return res < m;
}
signed main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	a[n + 1] = -1;
	for (int i = 1; i <= n; i ++ )
		cin >> a[i];
	sort(a + 2, a + n + 1);
	int l = 2, r = n, res = n + 1;
	while (l <= r)
	{
		int mid = l + r >> 1;
		if (check(mid)) r = mid - 1, res = mid;
		else l = mid + 1;
	}
	cout << a[res];
	return 0;
}
0