結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 46 ms
4,384 KB
testcase_08 AC 66 ms
4,600 KB
testcase_09 WA -
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,376 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]);
  for(int i=1;i<n;i+=2){
    int tmp=0;
    if(i==k) i++;
    tmp+=a[i];
    if(i+1==k) i++;
    tmp+=a[i];
    v.push_back(tmp);
  }
  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=0,r=n-1;
  if(!check(r,a)){
    cout<<-1<<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