結果

問題 No.451 575
ユーザー ikd
提出日時 2017-03-31 19:06:07
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 395 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 7,296 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-07-07 04:46:37
合計ジャッジ時間 7,145 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 12 RE * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
b=[]
n.times do
  b<< gets.to_i
end

l, r=1, 10**18
b.each_with_index do |e, i|
  if i.even?
    l, r=[1, e-r].max, e-l
  else
    l, r=[1, l-e].max, r-e
  end
  raise unless l<=r
end

if l>r
  puts (-1)
  exit(0)
end

a=[l]
(n-1).downto 0 do |i|
  if (i+1).even?
    a<< b[i]+a.last
  else
    a<< b[i]-a.last
  end
  raise unless a.last>0
end

puts a.size
a.reverse.map{|e| puts e}
0