---
# System prepended metadata

title: i | nums

---

```ver1
def max_sub_array(nums)
  max = nums[0]

  (1...nums.size).each do |i|
    nums[i] = [nums[i - 1] + nums[i], nums[i]].max
    max = [max, nums[i]].max
  end

  max
end
```

```ver2
def max_sub_array(nums)
  dp = [nums[0]]

  (1...nums.size).each do |i|
    dp[i] = [dp[i - 1] + nums[i], nums[i]].max
  end

  dp.max
end

```

# i | nums
# - | [1]

# i | nums
# - | [ 5, 4,-1, 7, 8]
# 1 | [ 5, 9,-1, 7, 8]
# 2 | [ 5, 9, 8, 7, 8]
# 3 | [ 5, 9, 8,15, 8]
# 4 | [ 5, 9, 8,15,23]

# i | nums
# - | [-2, 1,-3, 4,-1, 2, 1,-5, 4]
# 1 | [-2, 1,-3, 4,-1, 2, 1,-5, 4]
# 2 | [-2, 1,-2, 4,-1, 2, 1,-5, 4]
# 3 | [-2, 1,-2, 4,-1, 2, 1,-5, 4]
# 4 | [-2, 1,-2, 4, 3, 2, 1,-5, 4]
# 5 | [-2, 1,-2, 4, 3, 5, 1,-5, 4]
# 6 | [-2, 1,-2, 4, 3, 5, 6,-5, 4]
# 7 | [-2, 1,-2, 4, 3, 5, 6, 1, 4]
# 8 | [-2, 1,-2, 4, 3, 5, 6, 1, 5]


Travelling

```ruby=
n = gets.to_i
t = x = y = 0
ta = []
xa = []
ya = []

n.times do
  ti, xi, yi = gets.split.map(&:to_i)
  ta << ti
  xa << xi
  ya << yi
end

n.times do |i|
  dest = (xa[i] - x).abs + (ya[i] - y).abs
  room = ta[i] - t
  if dest % 2 != room % 2 || dest > room
    puts 'No'
    exit
  end

  t = ta[i]
  x = xa[i]
  y = ya[i]
end

puts 'Yes'
```
