結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー te-sh
提出日時 2017-12-25 17:40:05
言語 D
(dmd 2.109.1)
結果
AC  
実行時間 41 ms / 3,000 ms
コード長 724 bytes
コンパイル時間 703 ms
コンパイル使用メモリ 111,172 KB
実行使用メモリ 7,116 KB
最終ジャッジ日時 2024-06-12 23:16:24
合計ジャッジ時間 1,935 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.typecons;  // Tuple, Nullable, BigFlags

void main()
{
  auto rd = readln.split.to!(int[]), n = rd[0], m = rd[1];
  auto kp = readln.chomp.to!int;
  auto a = new int[](n-1);
  foreach (i; 0..n-1) a[i] = readln.chomp.to!int;

  a.sort!"a>b";

  if (n/2 == m) {
    writeln(a[$-1]);
    return;
  }

  auto calc(int i)
  {
    auto p = kp+a[i];
    auto b = (a[0..i] ~ a[i+1..$])[0..m*2];
    foreach (j; 0..m)
      if (b[j]+b[$-1-j] <= p) return true;
    return false;
  }

  auto bsearch = iota(n-1).map!(i => tuple(i, calc(i))).assumeSorted!"a[1]>b[1]";
  auto r = bsearch.lowerBound(tuple(0, false));
  writeln(r.empty ? -1 : a[r.back[0]]);
}
0