結果

問題 No.9 モンスターのレベル上げ
ユーザー vjudge1
提出日時 2025-09-05 09:25:39
言語 Crystal
(1.14.0)
結果
RE  
実行時間 -
コード長 757 bytes
コンパイル時間 12,005 ms
コンパイル使用メモリ 312,048 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 09:25:54
合計ジャッジ時間 13,038 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 RE * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n = gets.not_nil!.to_i
a = Array.new(n) { gets.not_nil!.to_i }
b = Array.new(n) { gets.not_nil!.to_i }

ans = Int32::MAX

n.times do |i|
  t = 0
  # Create a min-heap using an array sorted by first element
  ta = a.map { |val| {val, 0} }.sort_by { |pair| pair[0] }
  
  n.times do |j|
    # Get the smallest element (first in sorted array)
    p = ta.shift
    
    # Update the value and count
    new_val = p[0] + b[(i + j) % n] // 2
    new_count = p[1] + 1
    
    # Keep track of maximum count
    t = Math.max(t, new_count)
    
    # Insert back into sorted position using bsearch
    insert_index = ta.bsearch_index { |x| x[0] >= new_val } || ta.size
    ta.insert(insert_index, {new_val, new_count})
  end
  
  ans = Math.min(ans, t)
end

puts ans
0