結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー vjudge1
提出日時 2025-02-25 20:10:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 3,000 ms
コード長 811 bytes
コンパイル時間 2,395 ms
コンパイル使用メモリ 195,160 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-25 20:10:05
合計ジャッジ時間 4,748 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
template<typename T>istream&operator>>(istream&I,vector<T>&v){for(auto&i:v)I>>i;return I;}
template<typename T>ostream&operator<<(ostream&O,vector<T>&v){for(auto&i:v)O<<i<<' ';return O;}
namespace AC{
int n,m,l,r,mid,rk,ans,a[100010];
bool check(int x){
	rk=0;
	for(int i=1,j=n;i<j;){
		if(i==x)i++;
		if(j==x)j--;
		if(i>=j)break;
		if(a[i]+a[j]>a[0]+a[x])j--,rk++;
		i++;
	}
	return rk<m;
}
void solve(){
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>a[i];
	sort(a+1,a+n);
	n--;
	l=1,r=n;
	while(l<=r){
	    mid=l+r>>1;
	    if(check(mid))ans=mid,r=mid-1;
	    else l=mid+1;
	}
	if(ans)cout<<a[ans];
	else cout<<-1;
}
}
signed main(){
	int t=1;
	//cin>>t;
	while(t--)AC::solve();
}
0