結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー t8m8⛄️t8m8⛄️
提出日時 2017-04-28 02:08:09
言語 Nim
(2.0.2)
結果
AC  
実行時間 73 ms / 3,000 ms
コード長 737 bytes
コンパイル時間 4,861 ms
コンパイル使用メモリ 69,264 KB
実行使用メモリ 8,716 KB
最終ジャッジ日時 2023-09-12 12:46:56
合計ジャッジ時間 4,804 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 73 ms
8,616 KB
testcase_08 AC 71 ms
8,648 KB
testcase_09 AC 48 ms
8,708 KB
testcase_10 AC 47 ms
8,624 KB
testcase_11 AC 58 ms
8,648 KB
testcase_12 AC 48 ms
8,716 KB
testcase_13 AC 72 ms
8,512 KB
testcase_14 AC 70 ms
8,580 KB
testcase_15 AC 70 ms
8,544 KB
testcase_16 AC 69 ms
8,488 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import strutils, sequtils, algorithm

proc f(a: seq[int]; x, mid, n, m: int): bool =
  var
    val = x + a[mid]
    b = concat(a[0..mid-1], a[mid+1..n-2])
    (l, r) = (0, n-3)
    cnt = 0
  
  while l < r:
    var p = b[l] + b[r]
    if p > val:
      cnt.inc
      l.inc
      r.dec
    else:
      l.inc
    
  result = cnt < m

when isMainModule:
  var
    input = stdin.readline.split.map(parseint)
    (n, m) = (input[0], input[1])
    a = newSeq[int]()
    x = stdin.readline.parseint
  for i in 0..n-2:
    a.add stdin.readline.parseint
  a.sort(system.cmp)

  var (l, r) = (-1, n-2)
  while r - l > 1:
    var mid = (l + r) div 2
    if f(a, x, mid, n, m): r = mid
    else: l = mid

  echo if f(a, x, r, n, m): $a[r] else: "-1"
0