結果

問題 No.258 回転寿司(2)
ユーザー eigh8_t
提出日時 2015-08-01 00:13:04
言語 Ruby
(3.4.1)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 403 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 14,464 KB
最終ジャッジ日時 2024-11-06 18:48:50
合計ジャッジ時間 9,654 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 67
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.to_i
a = gets.split.map &:to_i
ra = Array.new(n+1,0)
rb = Array.new(n+1,0)
resulta = []
resultb = []
n.times{|i|
	ra[i+1] = rb[i] + a[i]
	rb[i+1] = [ra[i], rb[i]].max
	if ra[i] > rb[i]
		temp = resultb.dup
		resultb = resulta.dup
		resulta = temp.dup
	else
		resulta = resultb.dup
	end
	resulta.push(i+1)
}

if ra[n] > rb[n]
	puts ra[n]
	puts resulta*" "
else
	puts rb[n]
	puts resultb*" "
end
0