結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー te-shte-sh
提出日時 2017-12-25 17:40:05
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 46 ms / 3,000 ms
コード長 724 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 97,200 KB
実行使用メモリ 7,512 KB
最終ジャッジ日時 2023-09-03 17:48:32
合計ジャッジ時間 2,202 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 44 ms
7,460 KB
testcase_08 AC 42 ms
4,380 KB
testcase_09 AC 24 ms
7,432 KB
testcase_10 AC 24 ms
7,492 KB
testcase_11 AC 25 ms
7,460 KB
testcase_12 AC 24 ms
7,512 KB
testcase_13 AC 46 ms
7,464 KB
testcase_14 AC 43 ms
7,460 KB
testcase_15 AC 44 ms
7,456 KB
testcase_16 AC 45 ms
7,440 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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