結果

問題 No.9 モンスターのレベル上げ
ユーザー vjudge1
提出日時 2025-09-05 09:45:24
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 13,208 ms
コンパイル使用メモリ 314,720 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2025-09-05 09:45:43
合計ジャッジ時間 17,848 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 15 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

# Read n
n = gets.not_nil!.to_i

# Read array a (space-separated)
a = gets.not_nil!.split.map(&.to_i)

# Read array b (space-separated)  
b = gets.not_nil!.split.map(&.to_i)

temp = a.map { |val| {val, 0} }
ans = Int32::MAX

n.times do |i|
  # Use an array and sort it manually to simulate min-heap behavior
  arr = temp.dup
  arr.sort_by! { |(val, count)| val }
  
  ma = 0
  
  n.times do |j|
    # Get the smallest element (first element after sorting)
    element = arr.shift
    t, u = element
    
    # Add the modified element back and maintain sorted order
    new_val = t + b[(i + j) % n] // 2
    new_pair = {new_val, u + 1}
    
    # Insert in sorted position
    index = arr.bsearch_index { |(val, _)| val >= new_val } || arr.size
    arr.insert(index, new_pair)
    
    ma = Math.max(ma, u + 1)
  end
  
  ans = Math.min(ans, ma)
end

puts ans
0