結果

問題 No.2196 Pair Bonus
ユーザー simansiman
提出日時 2023-01-22 21:02:13
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 976 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 11,436 KB
実行使用メモリ 83,704 KB
最終ジャッジ日時 2023-09-07 05:17:41
合計ジャッジ時間 6,833 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,608 KB
testcase_01 AC 87 ms
15,388 KB
testcase_02 AC 85 ms
15,528 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

sum = 0
N.times do |i|
  sum += A[2 * i] + A[2 * i + 1] + X[i]
end

dp = Array.new(2 * N + 1, sum)

N.times do |i|
  temp = dp.dup

  0.upto(2 * N - 1) do |r_cnt|
    # dobule red
    # temp[r_cnt] += dp[r_cnt]

    # one red one blud
    if temp[r_cnt + 1] < dp[r_cnt] + (Y[i] - X[i]) + (B[2 * i] - A[2 * i])
      temp[r_cnt + 1] = dp[r_cnt] + (Y[i] - X[i]) + (B[2 * i] - A[2 * i])
    end

    # one blue one red
    if temp[r_cnt + 1] < dp[r_cnt] + (Y[i] - X[i]) + (B[2 * i + 1] - A[2 * i + 1])
      temp[r_cnt + 1] = dp[r_cnt] + (Y[i] - X[i]) + (B[2 * i + 1] - A[2 * i + 1])
    end

    # double blue
    if r_cnt + 2 <= 2 * N && temp[r_cnt + 2] < dp[r_cnt] + (B[2 * i] - A[2 * i]) + (B[2 * i + 1] - A[2 * i + 1])
      temp[r_cnt + 2] = dp[r_cnt] + (B[2 * i] - A[2 * i]) + (B[2 * i + 1] - A[2 * i + 1])
    end
  end

  dp = temp
end

pp dp.max
0