結果

問題 No.999 てん vs. ほむ
ユーザー gemmarogemmaro
提出日時 2020-11-07 08:55:07
言語 Ruby
(3.3.0)
結果
AC  
実行時間 247 ms / 2,000 ms
コード長 596 bytes
コンパイル時間 221 ms
コンパイル使用メモリ 11,456 KB
実行使用メモリ 33,788 KB
最終ジャッジ日時 2023-09-29 20:19:52
合計ジャッジ時間 5,841 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
15,260 KB
testcase_01 AC 78 ms
15,232 KB
testcase_02 AC 76 ms
15,096 KB
testcase_03 AC 79 ms
15,236 KB
testcase_04 AC 78 ms
15,084 KB
testcase_05 AC 79 ms
15,096 KB
testcase_06 AC 78 ms
15,104 KB
testcase_07 AC 78 ms
15,284 KB
testcase_08 AC 85 ms
15,484 KB
testcase_09 AC 228 ms
33,788 KB
testcase_10 AC 123 ms
20,812 KB
testcase_11 AC 111 ms
19,340 KB
testcase_12 AC 147 ms
22,020 KB
testcase_13 AC 242 ms
33,580 KB
testcase_14 AC 240 ms
33,632 KB
testcase_15 AC 245 ms
33,700 KB
testcase_16 AC 247 ms
33,760 KB
testcase_17 AC 231 ms
32,500 KB
testcase_18 AC 217 ms
33,096 KB
testcase_19 AC 227 ms
32,540 KB
testcase_20 AC 231 ms
32,620 KB
testcase_21 AC 242 ms
33,540 KB
testcase_22 AC 238 ms
33,428 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# frozen_string_literal: true

class Array
  def homura_point
    pairs = each_slice(2)
    
    left_sums = Array.new(N + 1, 0)
    right_sums = Array.new(N + 1, 0)

    pairs.each_with_index do |pair, index|
      left = pair[0]
      left_sums[index + 1] = left_sums[index] + left
    end

    pairs.reverse_each.with_index do |pair, index|
      right = pair[1]
      right_sums[N - index - 1] = right_sums[N - index] + right
    end

    left_sums.zip(right_sums).map { _1 + _2 }.max
  end
end

def solve
  2 * A.homura_point - A.sum
end

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

puts solve
0