結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー niiminiimi
提出日時 2018-10-08 01:59:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 20 ms / 3,000 ms
コード長 1,146 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 162,148 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 18:27:34
合計ジャッジ時間 1,991 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
typedef std::pair<int, int> P;

#define frep(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) frep(i, 0, (n))
#define rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define all(i, x) for(typeof(x.begin()) i = x.begin(); i != x.end(); i++)
#define pb push_back

const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const int MAX = 100010;
const int INF = 1e9;
const int MOD = 1000000007;
const string END = "\n";

void solve(){
	int n, m, a[MAX], ans;
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	int k = a[0];
	a[0] = -1;
	sort(a, a + n);
	a[0] = k;
	int left = 0, right = n;
	while(right - left > 1){
		int mid = (right + left) / 2;
		int tmp = a[mid] + a[0];
		int ll = 1, rr = n-1, cnt = 0;
		while(ll < rr){
			if(ll == mid) ll += 1;
			else if(rr == mid) rr -= 1;
			else if(a[rr] + a[ll] > tmp) ll += 1, rr -= 1, cnt += 1;
			else ll += 1;
		}
		if(cnt < m) right = mid;
		else left = mid;
	}
	if(right == n){
		ans = -1;
	}else{
		ans = a[right];
	}
	cout << ans << END;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	solve();
	return 0;
}
0