結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー WA_TLEWA_TLE
提出日時 2017-04-21 23:32:08
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 3,000 ms
コード長 1,260 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 65,856 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:24:09
合計ジャッジ時間 1,535 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
//#define scanf scanf_s
#define fir first
#define sec second
#define mp make_pair
#define mt make_tuple
#define pub push_back
using namespace std;
typedef long long int llint;
const llint one = 1;
const llint big = (one<<30);
const int mod=1000000007;
inline int gcd(int a,int b) { return b ? gcd(b, a % b) : a; }
int main(void){
	int N,M,me,q,gen=0,bmax,bmin,can;
	vector<int> po;
	scanf("%d %d",&N,&M);
	
	bmax=N-1;
	bmin=-1;
	scanf("%d",&me);
	for(int i=1;i<N;i++){
		scanf("%d",&q);
		po.pub(q);
	}
	if(N==2&&M==1){
		printf("%d\n",po[0]);return 0;
	}
	sort(po.rbegin(),po.rend());
	//ペアの相手の順位を最大化
	//8 2
	//4

	//6
	//5
	//4
	//3
	//2
	//1
	//1
	while(bmax-bmin>1){
		gen=(bmax+bmin)/2;
		int dow=N-2,lead=0,tei=me+po[gen],ok=1,it=0;
		for(lead=0;lead<M+it;lead++){
			if(lead==gen){it++;continue;}
			for(;dow>=0;dow--){
				if(dow==gen){continue;}
				if(dow<M+it){ok=0;break; }
				if(po[dow]+po[lead]>tei){dow--;break;}
			}
			if(ok==0){break;}
		}
		if(ok==1){bmax=gen;}//gen位の人と組んで敗退
		else{bmin=gen;}
	}
	if(bmin==-1){gen=-1;} 
	else{gen=(bmax+bmin)/2;}
	if(gen==-1){printf("-1\n");}
	else{printf("%d\n",po[gen]);}
 	return 0;
}

0