結果

問題 No.505 カードの数式2
ユーザー ueyukiueyuki
提出日時 2017-07-13 19:48:34
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 362 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-16 18:37:24
合計ジャッジ時間 4,138 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
12,160 KB
testcase_01 AC 88 ms
12,160 KB
testcase_02 AC 87 ms
12,160 KB
testcase_03 AC 87 ms
12,288 KB
testcase_04 AC 88 ms
12,288 KB
testcase_05 AC 93 ms
12,288 KB
testcase_06 AC 88 ms
12,160 KB
testcase_07 AC 89 ms
12,288 KB
testcase_08 AC 90 ms
12,032 KB
testcase_09 AC 88 ms
12,288 KB
testcase_10 AC 88 ms
12,288 KB
testcase_11 WA -
testcase_12 AC 89 ms
12,288 KB
testcase_13 WA -
testcase_14 AC 87 ms
12,160 KB
testcase_15 WA -
testcase_16 AC 85 ms
12,160 KB
testcase_17 WA -
testcase_18 AC 89 ms
12,160 KB
testcase_19 WA -
testcase_20 AC 88 ms
12,032 KB
testcase_21 AC 88 ms
12,288 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 89 ms
12,288 KB
testcase_31 AC 88 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

plus = []
diff = []
multi = []

max = [a[0]]

1.upto(n-1) do |i|
  plus << max[i-1] + a[i]
  diff << max[i-1] - a[i]
  multi << max[i-1] * a[i]
  
  if plus[i-1] > diff[i-1]
    max[i] = plus[i-1]
  else
    max[i] = diff[i-1]
  end

  if max[i] < multi[i-1]
    max[i] = multi[i-1]
  end
end

puts max[n-1]
0