結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー gigimegigime
提出日時 2017-04-21 23:13:49
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 3,000 ms
コード長 1,008 bytes
コンパイル時間 2,343 ms
コンパイル使用メモリ 171,932 KB
実行使用メモリ 8,352 KB
最終ジャッジ日時 2023-09-27 23:16:19
合計ジャッジ時間 5,747 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 46 ms
8,252 KB
testcase_08 AC 300 ms
8,228 KB
testcase_09 AC 305 ms
8,172 KB
testcase_10 AC 307 ms
8,228 KB
testcase_11 AC 305 ms
8,228 KB
testcase_12 AC 303 ms
8,292 KB
testcase_13 AC 325 ms
8,164 KB
testcase_14 AC 323 ms
8,352 KB
testcase_15 AC 310 ms
8,192 KB
testcase_16 AC 299 ms
8,224 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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