結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー pekempeypekempey
提出日時 2017-04-21 23:13:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 75,388 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 20:43:17
合計ジャッジ時間 1,909 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,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 43 ms
4,380 KB
testcase_08 AC 42 ms
4,376 KB
testcase_09 AC 28 ms
4,380 KB
testcase_10 AC 29 ms
4,376 KB
testcase_11 AC 29 ms
4,380 KB
testcase_12 AC 29 ms
4,376 KB
testcase_13 AC 43 ms
4,376 KB
testcase_14 AC 33 ms
4,376 KB
testcase_15 AC 33 ms
4,376 KB
testcase_16 AC 33 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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