結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー WA_TLE
提出日時 2017-04-21 23:32:08
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 26 ms / 3,000 ms
コード長 1,260 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 50,816 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 17:47:26
合計ジャッジ時間 1,552 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d %d",&N,&M);
      |         ~~~~~^~~~~~~~~~~~~~~
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d",&me);
      |         ~~~~~^~~~~~~~~~
main.cpp:26:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |                 scanf("%d",&q);
      |                 ~~~~~^~~~~~~~~

ソースコード

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