結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー vjudge1
提出日時 2025-02-23 18:22:23
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 27 ms / 3,000 ms
コード長 508 bytes
コンパイル時間 1,827 ms
コンパイル使用メモリ 163,032 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-23 18:22:26
合計ジャッジ時間 3,386 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:7:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d%d",&n,&m);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:8:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         for(int i=1;i<=n;++i)scanf("%d",&a[i]);
      |                              ~~~~~^~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int b[100005];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	sort(a+2,a+n+1);
	int L=2,R=n;
	while(L<=R){
		int mid=(L+R)>>1;
		int t=0;
		for(int i=2;i<=n;++i)if(i!=mid){
			b[++t]=a[i];
		}
		int gs=0,w=1;
		for(int i=t;i>=1;--i){
			while(w<i&&b[w]+b[i]<=a[1]+a[mid])++w;
			if(w<i){
				++gs;++w;
			}
		}
		if(gs>=m)L=mid+1;
		else R=mid-1;
	}
	if(L>n)puts("-1");
	else printf("%d\n",a[L]);
	return 0;
}
0