結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー dohatsutsu
提出日時 2017-04-21 23:19:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 57 ms / 3,000 ms
コード長 694 bytes
コンパイル時間 1,339 ms
コンパイル使用メモリ 159,964 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-20 17:43:23
合計ジャッジ時間 2,554 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int N,M,K;
int a[100000];

bool check(int x){
  int sum=K+a[x];

  int cnt=0;
  int h=0;
  
  if(h==x)h++;
  
  for(int i=N-1;i>=0;i--){
    if(i==x)continue;
    
    while(h<N && a[i]+a[h]<=sum){
      h++;
      if(h==x)h++;
    }

    if(h<i&&sum<a[i]+a[h]){
      cnt++;
      h++;
      if(h==x)h++;
    }
    
  }
  return ( cnt<M );
}

int main(){
  cin>>N>>M>>K;
  N--;
  for(int i=0;i<N;i++)cin>>a[i];    
  sort(a,a+N);
  int left=0,right=N-1,mid;
  while(left<right){
    mid=(left+right)/2;
    if(check(mid))right=mid;
    else left=mid+1;
  }

  if( check(N-1) ==false )    cout<<-1<<endl;
  else cout<<a[left]<<endl;
  return 0;
}

0