結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー beetbeet
提出日時 2017-04-21 23:31:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 863 bytes
コンパイル時間 1,125 ms
コンパイル使用メモリ 151,752 KB
実行使用メモリ 4,824 KB
最終ジャッジ日時 2023-09-27 23:24:05
合計ジャッジ時間 2,497 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 44 ms
4,556 KB
testcase_08 AC 46 ms
4,592 KB
testcase_09 AC 48 ms
4,600 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,m;
bool check(int k,int *a){
  vector<int> v;
  v.push_back(a[0]+a[k]);
  int tmp=0;
  for(int i=1;i<n;i++){
    if(i==k) i++;
    if(tmp==0) tmp=a[i];
    else{
      v.push_back(tmp+a[i]);
      tmp=0;
    }
  }
  //cout<<v.size()<<endl;
  //for(int k:v) cout<<"-"<<k<<endl;
  assert((int)v.size()==n/2);
  sort(v.begin(),v.end());
  auto p=upper_bound(v.begin(),v.end(),a[0]+a[k]);
  if(p==v.end()) return 1;
  return ((n/2)-(p-v.begin()))<m;
}
signed main(){
  cin>>n>>m;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a+1,a+n);
  int l=1,r=n-1;
  if(!check(r,a)){
    cout<<-1<<endl;
    return 0;
  }
  if(check(l,a)){
    cout<<a[l]<<endl;
    return 0;
  }
  while(l+1<r){
    int mid=(l+r)/2;
    if(check(mid,a)) r=mid;
    else l=mid;
  }
  cout<<a[r]<<endl;
  return 0;
}
0