class Yukicoder def initialize n = gets.to_i v = gets.chomp.split.map(&:to_i) dp = Array.new(n, 0) dp[0] = v[0] dp[1] = v[1] || 0 2.upto(n-1) do |i| dp[i] = dp[0..i-2].max + v[i] end puts dp.max end end Yukicoder.new