結果
問題 |
No.507 ゲーム大会(チーム決め)
|
ユーザー |
![]() |
提出日時 | 2022-05-08 16:36:20 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 262 ms / 3,000 ms |
コード長 | 651 bytes |
コンパイル時間 | 131 ms |
コンパイル使用メモリ | 7,296 KB |
実行使用メモリ | 14,848 KB |
最終ジャッジ日時 | 2024-07-08 04:59:11 |
合計ジャッジ時間 | 4,967 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 19 |
コンパイルメッセージ
Main.rb:36: warning: ambiguous first argument; put parentheses or a space even after `-' operator Syntax OK
ソースコード
N, M = gets.split.map(&:to_i) A = N.times.map { gets.to_i } B = A[1..-1].sort.reverse def f(idx) x = A[0] + B[idx] left = 0 right = B.size - 1 cnt = 0 while left < right if left == idx left += 1 next elsif right == idx right -= 1 next end v = B[left] + B[right] if v <= x right -= 1 else cnt += 1 left += 1 right -= 1 end end cnt < M end if not f(0) puts -1 exit end if f(B.size - 1) puts B.last exit end ok = 0 ng = B.size - 1 while (ok - ng).abs >= 2 idx = (ok + ng) / 2 if f(idx) ok = idx else ng = idx end end puts B[ok]