結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー dohatsutsudohatsutsu
提出日時 2017-04-21 23:19:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 59 ms / 3,000 ms
コード長 694 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 146,868 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 23:19:48
合計ジャッジ時間 2,620 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 53 ms
4,376 KB
testcase_08 AC 50 ms
4,376 KB
testcase_09 AC 33 ms
4,376 KB
testcase_10 AC 34 ms
4,376 KB
testcase_11 AC 34 ms
4,376 KB
testcase_12 AC 33 ms
4,380 KB
testcase_13 AC 59 ms
4,380 KB
testcase_14 AC 47 ms
4,376 KB
testcase_15 AC 47 ms
4,376 KB
testcase_16 AC 48 ms
4,380 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 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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