結果

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

テストケース

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

ソースコード

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];
	sort(a, a + n);
	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