結果

問題 No.507 ゲーム大会(チーム決め)
コンテスト
ユーザー myanta
提出日時 2017-04-22 01:52:24
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 901 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 567 ms
コンパイル使用メモリ 69,752 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2026-04-03 03:34:53
合計ジャッジ時間 1,608 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;


int n, m, k;
vector<int> a;


void min_u(int& d, int v)
{
	if(d<0 || d>v) d=v;
}


int solve_x(int i)
{
	int score, min_score, chk_score;
	int s, e;

	score=k+a[i];
	s=0;
	e=2*m;
	if(i>=2*m) e--;

	min_score=2000000001;
	for(;s<e;s++,e--)
	{
		if(s==i) s++;
		if(e==i) e--;
		chk_score=a[s]+a[e];
		min_u(min_score, chk_score);
	}

	if(min_score>score) return 0;
	return 1;
}


int solve(void)
{
	int s, e, c;
	int partner=-1;

	s=0;
	e=a.size()-1;
	for(;s<=e;)
	{
		c=(s+e)/2;
		if(solve_x(c))
		{
			min_u(partner, a[c]);
			s=c+1;
		}
		else
		{
			e=c-1;
		}
	}
	return partner;
}


int main(void)
{

	while(scanf("%d%d", &n, &m)==2)
	{
		scanf("%d", &k);
		a.resize(n-1);
		for(int i=0;i<n-1;i++)
		{
			scanf("%d", &a[i]);
		}
		sort(a.begin(), a.end(), greater<int>());

		printf("%d\n", solve());
	}

	return 0;
}
0