結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー oevloevl
提出日時 2019-03-21 23:54:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 3,000 ms
コード長 690 bytes
コンパイル時間 1,680 ms
コンパイル使用メモリ 172,020 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 05:50:29
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  rep(i, 0, N) cin >> a[i];
  sort(a.begin() + 1, a.end());
  int bl = 0;
  int br = N;
  int mid;
  while(abs(bl - br) > 1) {
    mid = (bl + br) / 2;
    int cnt = 0;
    int l = 1;
    int r = N - 1;
    while(l < r){
      if(l == mid) l++;
      else if(r == mid) r--;
      else if(a[l] + a[r] > a[0] + a[mid]) cnt++, l++, r--;
      else l++;
    }
    if(cnt < M) br = mid;
    else bl = mid;
  }
  cout << (br == N ? -1 : a[br]) << endl;
  return 0;
}
0