結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
|
提出日時 | 2017-04-22 10:53:15 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 1,715 ms / 3,000 ms |
コード長 | 1,288 bytes |
コンパイル時間 | 1,686 ms |
コンパイル使用メモリ | 164,852 KB |
実行使用メモリ | 21,620 KB |
最終ジャッジ日時 | 2024-06-12 18:50:09 |
合計ジャッジ時間 | 12,331 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm; import std.typecons, std.range, std.random, std.math, std.container; import std.numeric, std.bigint, core.bitop, core.stdc.string; void main() { auto s = readln.split.map!(to!int); auto N = s[0]; auto M = s[1]; auto a0 = readln.chomp.to!int; auto A = (N-1).iota.map!(_ => readln.chomp.to!int).array; A.sort(); bool ok(int m) { int x = a0 + A[m]; int cnt = 0; auto rbt = new RedBlackTree!(int, "a < b", true)(); foreach (i; 0..N-1) if (i != m) rbt.insert(A[i]); foreach (i; 0..N-1) { if (i == m) continue; if (rbt.equalRange(A[i]).empty) continue; rbt.removeKey(A[i]); auto ub = rbt.upperBound(x - A[i]); if (ub.empty) { rbt.insert(A[i]); continue; } auto y = ub.front; rbt.removeKey(y); cnt += 1; } return cnt < M; } if (!ok(N-2)) { writeln(-1); return; } int hi = N-2; int lo = 0; while (hi - lo > 1) { int mid = (hi + lo) / 2; if (ok(mid)) hi = mid; else lo = mid; } writeln( ok(lo) ? A[lo] : A[hi]); }