結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー niiminiimi
提出日時 2018-10-08 01:49:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,128 bytes
コンパイル時間 1,253 ms
コンパイル使用メモリ 160,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 18:27:08
合計ジャッジ時間 2,142 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 WA -
testcase_07 AC 20 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 12 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 20 ms
5,376 KB
testcase_14 AC 17 ms
5,376 KB
testcase_15 AC 17 ms
5,376 KB
testcase_16 AC 16 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 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, k, a[MAX], ans;
	cin >> n >> m;
	n -= 1;
	cin >> k;
	rep(i, n) cin >> a[i];
	sort(a, a + n);
	int left = 0, right = n;
	while(right - left > 1){
		int mid = (right + left) / 2;
		int tmp = a[mid] + k;
		int ll = 0, 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