結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー pekempey
提出日時 2017-04-21 23:13:12
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 53 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 74,624 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 15:16:40
合計ジャッジ時間 1,979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
	int n, m;
	std::cin >> n >> m;

	std::vector<int> a(n);
	for (int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	std::sort(a.begin() + 1, a.end());

	int ok = n;
	int ng = 0;

	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		int j = n - 1;
		int cnt = 0;
		for (int i = 1; i < n; i++) {
			if (i == mid) {
				continue;
			}
			if (j == mid) {
				j--;
			}
			if (i < j && a[i] + a[j] > a[0] + a[mid]) {
				j--;
				cnt++;
			}
		}
		if (cnt <= m - 1) {
			ok = mid;
		} else {
			ng = mid;
		}
	}
	if (ok == n) {
		std::cout << -1 << std::endl;
	} else {
		std::cout << a[ok] << std::endl;
	}
}
0