結果

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

ソースコード

diff #

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M,K;
vector<int> A;

int f(int m)
{
	multiset<int> st;
	FOR(i,0,N) if(i != m){
		st.insert(A [i]);
	}
	int res = 0;
	while(st.empty() == false){
		int x = *(--st.end());
		st.erase(--st.end());
		auto it = st.upper_bound(K + A [m] - x);
		if(it == st.end()) break;
		st.erase(it);
		res++;
	}
	return res;
}

int main()
{
	scanf("%d%d",&N,&M);
	N--;
	scanf("%d",&K);
	A.assign(N,0);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}
	sort(ALL(A));
	if(f(N - 1) >= M){
		puts("-1");
		return 0;
	}

	int ok = N - 1,ng = -1,mid;
	while(ok - ng > 1){
		mid = (ok + ng) / 2;
		if(f(mid) < M){
			ok = mid;
		}
		else{
			ng = mid;
		}
	}

	printf("%d\n",A [ok]);

	return 0;
}
0