結果

問題 No.999 てん vs. ほむ
ユーザー simansiman
提出日時 2020-02-28 21:34:24
言語 Ruby
(3.3.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 374 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 30,080 KB
最終ジャッジ日時 2024-04-21 18:03:39
合計ジャッジ時間 5,040 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,288 KB
testcase_01 AC 88 ms
12,032 KB
testcase_02 AC 91 ms
12,288 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 87 ms
12,288 KB
testcase_05 AC 87 ms
12,288 KB
testcase_06 AC 88 ms
12,160 KB
testcase_07 AC 87 ms
12,032 KB
testcase_08 AC 95 ms
12,544 KB
testcase_09 AC 233 ms
28,544 KB
testcase_10 AC 133 ms
16,640 KB
testcase_11 AC 118 ms
14,976 KB
testcase_12 AC 154 ms
19,072 KB
testcase_13 AC 246 ms
29,952 KB
testcase_14 AC 245 ms
30,080 KB
testcase_15 AC 246 ms
29,952 KB
testcase_16 AC 246 ms
29,824 KB
testcase_17 AC 231 ms
27,904 KB
testcase_18 AC 231 ms
27,520 KB
testcase_19 AC 232 ms
27,648 KB
testcase_20 AC 230 ms
27,776 KB
testcase_21 AC 243 ms
29,696 KB
testcase_22 AC 239 ms
29,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
A = gets.split.map(&:to_i)

R = A.each_slice(2).map { |a, b| a - b }
L = A.each_slice(2).map { |a, b| b - a }

SUM_R = [0]
SUM_L = [0]

R.inject(0) { |s, r| 
  v = s + r
  SUM_R << v
  v
}

L.reverse.inject(0) { |s, l|
  v = s + l
  SUM_L.unshift(v)
  v
}

ans = -Float::INFINITY

0.upto(N) do |i|
  v = SUM_L[i] + SUM_R[i]

  ans = v if ans < v
end

puts ans
0