結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー kzyKTkzyKT
提出日時 2017-03-19 21:39:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 3,000 ms
コード長 601 bytes
コンパイル時間 1,347 ms
コンパイル使用メモリ 146,652 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 07:31:05
合計ジャッジ時間 2,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

int main() {
  int n,k;
  scanf("%d%d",&n,&k);
  int a[n];
  for(int i=0; i<n; i++) scanf("%d",&a[i]);
  sort(a+1,a+n,greater<int>());
  int l=0,r=n;
  while(l+1!=r) {
    int m=(l+r)/2;
    int l2,r2=n-1,c=0;
    if(r2==m) r2--;
    for(l2=1; l2<r2; l2++,r2--) {
      if(l2==m) {
        r2++;
        continue;
      }
      if(r2==m) r2--;
      while(l2<r2&&a[l2]+a[r2]<=a[0]+a[m]) {
        r2--;
        if(r2==m) r2--;
      }
      if(l2>=r2) break;
      c++;
    }
    if(c>=k) r=m;
    else l=m;
  }
  printf("%d\n",l?a[l]:-1);
  return 0;
}
0