Skip to content

Instantly share code, notes, and snippets.

@kbutti
Last active October 12, 2017 02:41
Show Gist options
  • Select an option

  • Save kbutti/7e6743847d5390adfd8e to your computer and use it in GitHub Desktop.

Select an option

Save kbutti/7e6743847d5390adfd8e to your computer and use it in GitHub Desktop.
エンジニアでも恋がしたい!~転職初日にぶつかった女の子が同僚だった件~ 回答例
# エンジニアでも恋がしたい!~転職初日にぶつかった女の子が同僚だった件~
# パイザオンラインハッカソン4・Lite エン恋
# https://paiza.jp/poh/enkoi
# Q1
total = 0
total_line = gets.chomp.to_i
total_line.times do
m = gets.chomp
total += m.to_i
end
puts total
# Q2
total_line = gets.chomp.to_i
e = {'T'=>0, 'S'=>1, 'P'=>2}
cost = []
total_line.times do
m = gets.chomp.split(' ').map(&:to_i)
cost << 0 and next if m[e['T']] < m[e['S']] # plenty
cost << m[e['P']] * (m[e['T']] - m[e['S']]) # fill up
end
puts cost.inject(:+)
# Q3 (Time over)
t, n = gets.chomp.split(' ').map(&:to_i)
m = []
n.times do
m << gets.chomp.to_i
end
critical = 0
i = 0
while i < (n - t + 1)
hit = m.slice(i, t).inject(:+)
critical = hit if hit > critical
i += 1
end
puts critical
# Q3 (Improved)
t, n = gets.chomp.split(' ').map(&:to_i)
m = []
n.times do
m << gets.chomp.to_i
end
last_hit = critical = m.slice(0, t).inject(:+)
i = 0
while i < (n - t)
last_hit = last_hit - m[i] + m[i + t]
critical = last_hit if last_hit > critical
i += 1
end
puts critical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment