Last active
October 12, 2017 02:41
-
-
Save kbutti/7e6743847d5390adfd8e to your computer and use it in GitHub Desktop.
エンジニアでも恋がしたい!~転職初日にぶつかった女の子が同僚だった件~ 回答例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # エンジニアでも恋がしたい!~転職初日にぶつかった女の子が同僚だった件~ | |
| # パイザオンラインハッカソン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